Android O can't receive broadcast Intent.ACTION_NEW_OUTGOING_CALL

心不动则不痛 提交于 2020-01-23 11:38:39

问题


In my application, I can receive android.intent.action.PHONE_STATE but can't receive Intent.ACTION_NEW_OUTGOING_CALL on android O. If I use android N or android M everything work fine.

I have register first broadcast in AndroidManifest file and second in foreground service, but none of them can receive Intent.ACTION_NEW_OUTGOING_CALL, only can receive android.intent.action.PHONE_STATE.

If anyone know how to fix it, please post your answer, thanks in advance.


回答1:


But I am still confused, because my phone not ask me to give the permission but work fine. Maybe a bug or feature of android O ?

Its a feature of Android O.

Previously, when you request a permission (android.permission.READ_PHONE_STATE) of a permission group (PHONE) and the user grants it, you are allowed to use any permission (android.permission.PROCESS_OUTGOING_CALLS etc.) of that permission group (PHONE) freely(without requesting to user again).

Now from Android O, even if your app already holds permission (android.permission.READ_PHONE_STATE) of a permission group(PHONE), you need to call requestPermission again for other permission (android.permission.PROCESS_OUTGOING_CALLS) of the same group. This will not prompt user to grant permission(android.permission.PROCESS_OUTGOING_CALLS) and the permission will automatically be granted if you already hold another permission (android.permission.READ_PHONE_STATE) of same permission group(PHONE).




回答2:


After some test, I fix it by add:

ActivityCompat.requestPermissions(activity, Manifest.permission.PROCESS_OUTGOING_CALLS, requestCode)

But I am still confused, because my phone not ask me to give the permission but work fine. Maybe a bug or feature of android O ?



来源:https://stackoverflow.com/questions/46151569/android-o-cant-receive-broadcast-intent-action-new-outgoing-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!