035179593513 [email protected]

If you want to be able to react to incoming calls, e.g. to block them on certain conditions without implementing all the functions the default phone handler has. The Solution is to become the default Call Screening Service.

android/app/main/AndroidManifest.xml


Call screening service:

public class MyCallScreeningService extends CallScreeningService {

@Override
public void onScreenCall(@NonNull Call.Details callDetails) {
/// handle incoming call ...
}

}

How to check if the Application has the Role Call Screening:

RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
roleManager.isRoleHeld(RoleManager.ROLE_CALL_SCREENING);

How to request the user to make the App the Call Screening Service:

RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
startActivityForResult(intent,CALL_SCREENING_INTENT_CODE);

// CALL_SCREENING_INTENT_CODE can be any int -> used to react to result with:

@Overide
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == CALL_SCREENING_INTENT_CODE){
// ... do something
}
}

Further information: https://developer.android.com/reference/android/telecom/CallScreeningService

en_USEnglish