Originally published on my blog.
TL;DR
In this post, I'll show you step by step how to make a native Android app that can block certa...
For further actions, you may consider blocking this person and/or reporting abuse
It is not blocking the call for me..
Th ring continue to ring until i cut the phone.
I am using exact same code from github.
And testing on Android studio emulator pixel 2.
Can anyone please help...
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:
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");
}
}
hii,its work fine, but it's block the calls even if we close the application
What are you referring to with 'destroyed'?
i want to de-register the broadcast receiver after press the back button.that is once i exit from app blocking should not be happen.
And what have you tried so far?
It is not working on Motorola G5S plus. What can be wrong? Permissions are granted but incoming call is not blocked. G5S plus is running android 7.1.1 API level 25
What do you get in the logs when you debug the app?
I get a call notification that disappears after less of a second. Sometimes the notification will not pop-up at all. But it is still useful. Thx
This actually means it's working for you.
I want the calls should get blocked .. how I can achieve that..?
What have you tried so far?
Thank you for your response.. I want to block the outgoing calls.. when my application is going in background.. I have written the following code with the help of stackoverflow but the code is not working:-
Will be waiting for your response.. thank you in advance.
public class OutgoingCallBlocking extends BroadcastReceiver {
}
Hi Nick, does this work in the background when the app is off?
Thanks
Yes.
Now this is when there is an incoming call, but when there is an outgoing call and I do not want the outgoing number to appear. How will this be done
What have you tried so far?
Yay! Finally, someone broke the jinx of the code, even I spent a lot of time on StackOverflow, for this, thank you Nikola!
Works like a charm!
Great, I'm glad this helped you 👍
when I get a call, instead of closing the call my app gets closed. AND the part that says "PERMISSION_REQUEST_READ_PHONE_STATE" is in red. any help?
It won't work,it will ask MODIFY_PHONE_STATE permission to block the calls.Now android is not allowing MODIFY_PHONE_STATE permissions to third party applications.
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");
}
}
Exactly, did you find any solution for this?
Nope
hello,i use this code but its not working for me,i used oneplus5 phone.in logcat its show ClassCastException for this line= telephonyService = (ITelephony) m.invoke(tm);
Did you add it through reflection as noted in the post?