# Print output for @column tags ?> CallScreeningService - Android SDK | Android Developers

Most visited

Recently visited

CallScreeningService

public abstract class CallScreeningService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.telecom.CallScreeningService


This service can be implemented by the default dialer (see TelecomManager#getDefaultDialerPackage()) or a third party app to allow or disallow incoming calls before they are shown to a user. A CallScreeningService can also see outgoing calls for the purpose of providing caller ID services for those calls.

Below is an example manifest registration for a CallScreeningService.

 <service android:name="your.package.YourCallScreeningServiceImplementation"
          android:permission="android.permission.BIND_SCREENING_SERVICE">
      <intent-filter>
          <action android:name="android.telecom.CallScreeningService"/>
      </intent-filter>
 </service>
 
 

A CallScreeningService performs two functions:

  1. Call blocking/screening - the service can choose which calls will ring on the user's device, and which will be silently sent to voicemail.
  2. Call identification - services which provide call identification functionality can display a user-interface of their choosing which contains identifying information for a call.

Becoming the CallScreeningService

Telecom will bind to a single app chosen by the user which implements the CallScreeningService API when there are new incoming and outgoing calls.

The code snippet below illustrates how your app can request that it fills the call screening role.

 {@code
 private static final int REQUEST_ID = 1;

 public void requestRole() {
     RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
     Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
     startActivityForResult(intent, REQUEST_ID);
 }

 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == REQUEST_ID) {
         if (resultCode == android.app.Activity.RESULT_OK) {
             // Your app is now the call screening app
         } else {
             // Your app is not the call screening app
         }
     }
 }
 

Summary

Nested classes

class CallScreeningService.CallResponse

 

Constants

String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

Inherited constants

Public constructors

CallScreeningService()

Public methods

IBinder onBind(Intent intent)

Return the communication channel to the service.

abstract void onScreenCall(Call.Details callDetails)

Called when a new incoming or outgoing call is added which is not in the user's contact list.

boolean onUnbind(Intent intent)

Called when all clients have disconnected from a particular interface published by the service.

final void respondToCall(Call.Details callDetails, CallScreeningService.CallResponse response)

Responds to the given incoming call, either allowing it, silencing it or disallowing it.

Inherited methods

Constants

SERVICE_INTERFACE

public static final String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

Constant Value: "android.telecom.CallScreeningService"

Public constructors

CallScreeningService

public CallScreeningService ()

Public methods

onBind

public IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Returns
IBinder Return an IBinder through which clients can call on to the service.

onScreenCall

public abstract void onScreenCall (Call.Details callDetails)

Called when a new incoming or outgoing call is added which is not in the user's contact list.

A CallScreeningService must indicate whether an incoming call is allowed or not by calling CallScreeningService#respondToCall(Call.Details, CallScreeningService.CallResponse). Your app can tell if a call is an incoming call by checking to see if Call.Details#getCallDirection() is Call.Details#DIRECTION_INCOMING.

Note: The Call.Details instance provided to a call screening service will only have the following properties set. The rest of the Call.Details properties will be set to their default value or null.

Only calls where the Call.Details#getHandle() Uri#getScheme() is PhoneAccount#SCHEME_TEL are passed for call screening. Further, only calls which are not in the user's contacts are passed for screening. For outgoing calls, no post-dial digits are passed.

Parameters
callDetails Call.Details: Information about a new call, see Call.Details. This value cannot be null.

onUnbind

public boolean onUnbind (Intent intent)

Called when all clients have disconnected from a particular interface published by the service. The default implementation does nothing and returns false.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Returns
boolean Return true if you would like to have the service's onRebind(Intent) method later called when new clients bind to it.

respondToCall

public final void respondToCall (Call.Details callDetails, 
                CallScreeningService.CallResponse response)

Responds to the given incoming call, either allowing it, silencing it or disallowing it.

The CallScreeningService calls this method to inform the system whether the call should be silently blocked or not. In the event that it should not be blocked, it may also be requested to ring silently.

Calls to this method are ignored unless the Call.Details#getCallDirection() is Call.Details#DIRECTION_INCOMING.

Parameters
callDetails Call.Details: The call to allow.

Must be the same Call.Details which was provided to the CallScreeningService via onScreenCall(android.telecom.Call.Details). This value cannot be null.

response CallScreeningService.CallResponse: The CallScreeningService.CallResponse which contains information about how to respond to a call. This value cannot be null.