How to Block Incomi...
 

How to Block Incoming Call in Android P (API 28)  


Mike
Posts: 1
 Mike
Guest
(@Mike)
Joined: 2 months ago

I am developing an android app to block the incoming calls. Till API 27 (OREO MR1), I have used the reflection method (iTelephony) to block the incoming calls. But in Android Pie, reflections are deprecated. So the iTelephony method is not working in Android P version. Is there any working method to block incoming call in API >= 28.

1 Reply
admin
Posts: 93
Admin
(@mjv119gmail-com)
Member
Joined: 5 years ago

In Android Pie, there is an official way to block the incoming calls using endcall() function in TelecomManager,

https://developer.android.com/reference/android/telecom/TelecomManager#endCall()

To use this function you need ANSWER_PHONE_CALLS permission. This is categorized as dangerous permission, so you need to request this permission during runtime instead of adding in manifest file.

if (checkSelfPermission(Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_GRANTED) {
TelecomManager tcm = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
if (tcm != null) {
try {
if (incomingCallNumber != null) {
tcm.endCall();
Log.d(TAG, "Incoming Call Blocked " + incomingCallNumber);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

EDIT: endcall() function is deprecated in Android Q (API 29), so you can use this method only in Android Pie (API 28).

Reply

Leave a reply


 
Preview 0 Revisions Saved
Share: