Google is committed to advancing racial equity for Black communities. See how.

CallScreeningService

abstract class CallScreeningService : Service
kotlin.Any
   ↳ 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 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.

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

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);
  }
 
  &amp;#64;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
          }
      }
  }
  &lt;/pre&gt;
   24</code>

Summary

Nested classes
open

Constants
static String

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

Inherited constants
Public constructors

Public methods
open IBinder?
onBind(intent: Intent!)

abstract Unit
onScreenCall(callDetails: Call.Details)

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

open Boolean
onUnbind(intent: Intent!)

Unit

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

Inherited functions

Constants

SERVICE_INTERFACE

Added in API level 24
static val SERVICE_INTERFACE: String

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

Value: "android.telecom.CallScreeningService"

Public constructors

<init>

Added in API level 24
CallScreeningService()

Public methods

onBind

Added in API level 24
open fun onBind(intent: Intent!): IBinder?
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.
Return
IBinder? Return an IBinder through which clients can call on to the service.

onScreenCall

Added in API level 24
abstract fun onScreenCall(callDetails: Call.Details): Unit

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

Added in API level 24
open fun onUnbind(intent: Intent!): Boolean
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.
Return
Boolean Return true if you would like to have the service's onRebind method later called when new clients bind to it.

respondToCall

Added in API level 24
fun respondToCall(
    callDetails: Call.Details,
    response: CallScreeningService.CallResponse
): Unit

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.