问题
Background
For a very long time, there wasn't an official API for blocking calls on Android.
What developers did for CallerId and call-blocking apps, is to use some reflection tricks, as shown here.
The problem
It seems no blocking app works on Android P DP3 (tested on Pixel 2). Even very popular apps such as TrueCaller fail to block calls.
I believe this is because it might be replaced with an official API, as there are some articles that talk about built in call blocking capability for users:
https://www.gsmarena.com/android_p_may_introduce_stricter_call_blocking-news-29940.php
What I've found
The only solution that could replace it, is by extending InCallService class, but by doing so you must also have your app become the default dialer app:
In addition to implementing the InCallService API, you must also declare an activity in your manifest which handles the Intent.ACTION_DIAL intent.
Not only that, but only one app can be set as such at a time, so the user can't choose multiple callerId and/or call-blocking apps.
Seeing that I can't find an alternative, and that now it's the best time to request such a thing, I've also requested it here.
The question
Is there another alternative for rejecting calls?
Does Google provide now with an official function to do it?
回答1:
It should be quite easy with the new Android P API. Your app needs to request the permission Manifest.permission.ANSWER_PHONE_CALLS
. Then you can call the method endCall
of TelecomManager
class doc here.
来源:https://stackoverflow.com/questions/51085831/is-there-a-new-official-api-for-rejecting-calls-on-android