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