简体   繁体   中英

App doesn't appear in the “Do Not Disturb Access” screen in Android 7/8

I have an app that needs to be able to override Do Not Disturb access in Android 7/8. I have code that checks for the permission and opens the Do Not Disturb Access screen if it's not detected:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && !notificationManager.isNotificationPolicyAccessGranted()) {

        Intent intent = new Intent(
                android.provider.Settings
                        .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        context.startActivity(intent);

As well, I have this permission set up in the manifest:

<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

This works fine on some devices and in all the virtual devices I've used it on, but on other devices, like a Pixel running Android 8, my app simply does not appear in the Do Not Disturb Access list and therefore the user cannot grant it the ability to override Do Not Disturb. Is there a specific permission or something Android is looking for to have an App appear in the Do Not Disturb Access list consistently?

I know this doesn't help, but I've been successfully running an app on a few Pixels without problem. But one client has the exact same problem you are describing. I have the same code/permissions as you.

Edit - my client fixed his own problem. On his phone he has apps split between work and personal. Changing my app to personal made it appear in the list. Maybe this is your problem too.

According to the documentation, that's not possible.

ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS

Activity Action: Show Do Not Disturb access settings.

Users can grant and deny access to Do Not Disturb configuration from here. Managed profiles cannot grant Do Not Disturb access . See NotificationManager.isNotificationPolicyAccessGranted() for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM