Looking at previous solutions for this problem are now depreciated as of api 29(Android 10). Has anyone been able to get the incoming phone number on for api 29. Apparently now to do this you need to use CallScreeningService
Asked
Active
Viewed 2,701 times
1 Answers
0
Yes, implement the class and add the necessary permission below in the manifest:
<service
android:name=".CallScreeningService"
android:permission="android.permission.BIND_SCREENING_SERVICE">
<intent-filter>
<action android:name="android.telecom.CallScreeningService" />
</intent-filter>
</service>
Within onScreenCall(Call.Details details)
you can call details.getHandle()
which returns the telephone number of the incoming call. This will only get called if the number cannot be matched to the contact information existing on the device.
@Override
public void onScreenCall(Call.Details details) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if(details.getCallDirection() == Call.Details.DIRECTION_INCOMING) {
CallResponse.Builder response = new CallResponse.Builder();
response.setDisallowCall(false);
response.setRejectCall(false);
response.setSilenceCall(false);
response.setSkipCallLog(false);
response.setSkipNotification(false);
details.getHandle(); //This is the calling number
respondToCall(details, response.build());
}
}
}

Jared Forth
- 1,577
- 6
- 17
- 32

Thomas Rogers
- 44
- 5
-
1Does this really work for all calls, since the documentation states "Further, only calls which are not in the user's contacts are passed for screening. " -> https://developer.android.com/reference/android/telecom/CallScreeningService#onScreenCall(android.telecom.Call.Details) – Christopher Feb 09 '21 at 12:58
-
1Correct this is only called when the incoming number is not in the devices Contacts list – Thomas Rogers Feb 10 '21 at 20:17
-
1This implementation will only fetch the Phone Numbers that are Unknown or Not saved in your Contacts. Doesn't answer the question yet completely. – Nandhan Thiravia May 06 '21 at 15:15