Android 7.0/API24: How to check for notification access (Settings.Secure.enabled_notification_listeners)

浪尽此生 提交于 2019-12-25 08:00:10

问题


In Android 6.0/API23 and earlier, the following used to work:

String settingEnabled = android.provider.Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners");

In Android 7.0 Nougat/API24 this seems to be no longer supported, because the code above returns null.

It actually was never mentioned here: https://developer.android.com/reference/android/provider/Settings.Secure.html

How do we check if our app has notification access in Android 7.0 Nougat API24?

Edit: It seems that actually that after you first gained the access in the settings, the code above returns the correct state. But not on the initial request after installation.


回答1:


Use this:

Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages (context);


来源:https://stackoverflow.com/questions/39654943/android-7-0-api24-how-to-check-for-notification-access-settings-secure-enabled

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