Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the new Notification Settings in Android 4.3 through Code

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

like image 476
adefran83 Avatar asked Aug 13 '13 14:08

adefran83


2 Answers

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"));
like image 160
CommonsWare Avatar answered Nov 15 '22 22:11

CommonsWare


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

like image 25
Charles Madere Avatar answered Nov 15 '22 21:11

Charles Madere