I'm using the >=4.3 NotificationListenerService
to access notifications. On the first start, my app takes the user to the "Access Notifications" system panel, but I'd like to take the user there whenever the checkbox for my app in "Access Notifications" is disabled. I haven't found a isNotificationAccessEnabled()
-method anywhere, but I definitely know that it's possible because apps like Krome do this, too.

- 3,504
- 2
- 39
- 78
4 Answers
Edit June 15th, 2016
I'm not sure which version of the support library this was added to, but it looks like this functionality is now built in. Simply use:
NotificationManagerCompat.getEnabledListenerPackages(context);
(link to docs)
This returns a Set<String>
that you can iterate through to find your package name. Note however that I haven't personally tested this. But it looks like it's probably preferred to use this in place of my old solution below.
Old Solution
This code is working for my app:
ContentResolver contentResolver = context.getContentResolver();
String enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
String packageName = context.getPackageName();
// check to see if the enabledNotificationListeners String contains our package name
if (enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName))
{
// in this situation we know that the user has not granted the app the Notification access permission
throw new Exception();
}
else
{
doSomethingThatRequiresNotificationAccessPermission();
}
Typical values that I've seen for the enabledNotificationsListeners
String
look like this:
- User has given none of their apps Notification access permission
null
or""
- User has given one app Notification access permission
"com.woodblockwithoutco.remotecontrollerexample/com.woodblockwithoutco.remotecontrollerexample.RemoteControlService"
- User has given two apps Notification access permission
"com.scootrnova.android/com.scootrnova.android.ListenerService:com.woodblockwithoutco.remotecontrollerexample/com.woodblockwithoutco.remotecontrollerexample.RemoteControlService"
This implementation is very straightforward and works great :)
P.S. I got the idea to use the hardcoded "enabled_notification_listeners" String from this answer.

- 6,642
- 5
- 35
- 34
-
2This is working for me very nicely. The only thing I needed to change was String packageName = context.getPackageName(); to **String packageName = MyService.class.getName();** since I was checking it in my launcher – Nlinscott Sep 05 '14 at 04:44
-
1On my test device (LG G3) the string contains the package name and the Listener's class name. So if you only have one NotificationListenerService, then looking for either string would work. The string returned by "Settings.Secure.getString" is a colon (:) delimited list of classes in the following format: com.example.myapp/com.example.myapp.mynotificationlistener – Mike May 19 '15 at 14:51
-
3On a stock Android 6, without having ever enabled notification listeners for any apps, enabledNotificationListeners does indeed become NULL. – Cumbayah Nov 12 '15 at 21:49
-
This is working but not sure if this is the correct way since the enabled_notification_listeners is a hidden – albanx Dec 13 '15 at 17:17
-
NotificationManagerCompat.getEnabledListenerPackages(context); returns an empty list for me – ir2pid Jun 30 '16 at 06:09
-
2NotificationManagerCompat.getEnabledListenerPackages(context) best solution on SO to check it. Thanks for the update of the answer. – atapi19 Aug 12 '16 at 10:17
-
It looks like that as long as the notification listener has `android:enabled="true"`, `NotificationManagerCompat.getEnabledListenerPackages(context)` will include my package name, regardless of whether user has granted it access. – P. B. Apr 02 '17 at 20:55
Starting with Android 8.1 (SDK 27) you can call isNotificationListenerAccessGranted on the NotificationManager. This is the correct API to use. Older Android versions should use getEnabledListenerPackages as a second best option. Relying on your listener callbacks can give incorrect results. See explanation below.
Im developer of Krome. What have I done to check if service is enabled is add public static variable that changes to true in onBind method and to false in unbind. That is how this service work.
Edit:
public static boolean isNotificationAccessEnabled = false;
@Override
public void onListenerConnected() {
isNotificationAccessEnabled = true;
}
@Override
public void onListenerDisconnected() {
isNotificationAccessEnabled = false;
}

- 675
- 1
- 6
- 14

- 804
- 6
- 11
-
Hi Damian, awesome, thank you very much for your answer, I never expected to get a reply from "the man himself" :-)! I'll try this and let you know if you can figure it out by myself. – Nick Aug 08 '13 at 09:06
-
While you're here :-P, I've got another quick question. I have posted it as a new SO-question [here](http://stackoverflow.com/questions/18122198/reliable-way-of-retrieving-statusbarnotification-details-title-notification-te). It would be great if you could take a look at it. I love Krome, by the way, it's beautifully designed and works really well! – Nick Aug 08 '13 at 09:16
-
7Just for anyone else who is interested, this is my code: `public static boolean isNotificationAccessEnabled = false; @Override public IBinder onBind(Intent mIntent) { IBinder mIBinder = super.onBind(mIntent); isNotificationAccessEnabled = true; return mIBinder; } @Override public boolean onUnbind(Intent mIntent) { boolean mOnUnbind = super.onUnbind(mIntent); isNotificationAccessEnabled = false; return mOnUnbind; }` in combination with a check for isNotificationAccessEnabled in my main activity. – Nick Aug 08 '13 at 09:50
-
2This solution works only when you check first time, because system call onBind callback only once for NotificationListenerService. If you try uncheck (onUnbind will be called) and then check again, onBind will not be called second time thus `isNotificationAcessAnabled` will be false. – klimat Feb 06 '15 at 10:06
-
2This is not a reliable solution. Android will call onBind/onUnbind most of the time, but it is not 100% by design per the android framework team: https://groups.google.com/forum/#!msg/android-developers/2IegSgtGxyE/iXP3lBCH5SsJ – Jim Vitek Mar 05 '15 at 19:50
-
@JimVitek @mklimek I edited the answer to use `onListenerConnected()` and `onListenerDisconnected()` instead – Louis CAD Dec 07 '17 at 15:24
-
1This is still not a reliable solution. There are cases in which the user has granted access to the notifications, but the onListenerConnected() method won't be called. I've run into this case many times while debugging my own app which is also using a NotificationListenerService. Having the listener connected and having the access to notficiations granted is NOT the same thing. – shai tibber Jan 07 '18 at 20:55
-
Thanks! In my case onListenerConnected was called but onListenerDisconnected was not being called. But onDestroy was called so I moved my code to onDestroy. – Usman May 01 '18 at 10:45
-
That's unlikely since `onListenerDisconnected()` is the only method that is called inside `onDestroy()`. See also my post below. Relying on these callbacks to know if the user has granted access to notficiations is not giving correct results. – Rvb84 Apr 15 '21 at 07:48
Works well with slightly modified @Damians answer
public class NotifyListener extends NotificationListenerService{
public static boolean listnerConnected = false;
@Override
public IBinder onBind(Intent intent) {
Log.d(name,"onBind Called");
listnerConnected = true;
return super.onBind(intent);
}
@Override
public void onDestroy()
{
super.onDestroy();
Log.e("destroy", "called");
listnerConnected = false;
}
}

- 179
- 2
- 10
Starting with Android 8.1 (SDK 27) you can call isNotificationListenerAccessGranted on the NotificationManager. This is the correct API to use, not the one of the accepted answer. See explanation below.
Like shai tibber also already said the accepted answer is incorrect.
onListenerConnected()
and onListenerDisconnect()
can get called even when there is no NotificationListener access granted. So relying on this callbacks to set a boolean will give wrong results. And getEnabledListenerPackages(context)
will just return all the packages that have an enabled notification listener defined in there AndroidManifest (android:enabled=true). It's NOT directly related to the user access. The documentation states exactly that:
Get the set of packages that have an enabled notification listener component within them.

- 675
- 1
- 6
- 14