问题
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