8

How can I access this through code? So I can open it for the users automatically and they don't have to hunt through the Security settings to enable it.

I am unable to find it in Android Studio using startActivity(new Intent(Settings.<>));, where <> is the list of setting screens.

Notification Access Screen

Image courtesy of Android Police

Community
  • 1
  • 1
adefran83
  • 653
  • 7
  • 10
  • It is possible that this will only appear on the Security screen in Settings when 1+ notification listeners are installed. – CommonsWare Aug 13 '13 at 14:55
  • I've installed my app with the Notification Listener as well as "ActiveNotifications for Android" app (which has the settings screen pop up when you open the app) but it still doesn't show up. – adefran83 Aug 13 '13 at 14:57
  • I feel really dumb, it does show up once you have one installed... however I would still like to automatically open it for the user so they don't have to hunt for it. will edit my question to reflect that. – adefran83 Aug 13 '13 at 15:02

2 Answers2

23

There is an outstanding bug in Android 4.3 where the notification listener screen action is not listed in Settings. The current workaround is:

startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks! Worked perfectly. – adefran83 Aug 13 '13 at 15:09
  • I used this in my app but now it opens every time the app starts. Is there a way to make it open only if the user hasn't selected the app for access? – otaku Jun 15 '14 at 19:54
  • 1
    @AbhyudayaSrinet: I have not played around with a `NotificationListenerService`. You would need to find out whether you are enabled as a listener or not, and only start the activity if you are not enabled as a listener. I have not researched this area to know how exactly to do that. – CommonsWare Jun 15 '14 at 19:55
  • 2
    Ok I found what I needed.. In case anyone needs directions in future, this is the [Question](http://stackoverflow.com/questions/18097583/check-for-access-to-notifications-using-notificationlistenerservice) and I also added this line in my main activity if(!NLService.isNotificationAccessEnabled) startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")); – otaku Jun 15 '14 at 20:12
2

The bug that @CommonsWare mentioned has been fixed as of Android 5.1 (API 22). You can now use this to bring the user to the Notification access screen:

startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));

I've tested this across multiple Genymotion instances (4.3, 4.4, and 5.1) as well as a Galaxy S3 running 4.3, and this solution has worked perfectly in each case.

Strangely however Android Studio does give me a warning when I use this field on pre-API 22 projects, despite the fact that it works without problems:

Field requires API 22 (current min is 18): android.provider.Settings#ACTION_NOTIFICATION_LISTENER_SETTINGS

I believe that this warning should be able to be safely ignored, similarly to how you can use values from Build.VERSION_CODES on any version of the platform.

Link to the documentation: Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS

Charles Madere
  • 6,642
  • 5
  • 35
  • 34