Skip to content

Instantly share code, notes, and snippets.

@coolya
Last active September 10, 2020 02:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coolya/305062e405ba8fb058fc to your computer and use it in GitHub Desktop.
Save coolya/305062e405ba8fb058fc to your computer and use it in GitHub Desktop.
How to check if you app has permission to get notification service listener
boolean hasNotificationAccess()
{
ContentResolver contentResolver = this.getContentResolver();
String enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
String packageName = this.getPackageName();
// check to see if the enabledNotificationListeners String contains our package name
return !(enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment