DEV Community

Discussion on: How to make a native Android app that can block phone calls

Collapse
 
tmjansson profile image
Mikael Jansson

Just for info.
Works like charm on my Moto G3 runnnig V6.0.1 Android.

But on Moto G7 Power running Android V9, I don't get caller ID and I get:

  • java.lang.SecurityException: MODIFY_PHONE_STATE permission required.
Collapse
 
ishan001 profile image
Ishan Khandelwal

Use TelecomManger to end call programatically for Android 9 and above using ANSWER_PHONE_CALL permission.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_GRANTED) {
success = tm.endCall();
Log.d("call state", "call end");
}
}