Home » Android » Accessing the new Notification Settings in Android 4.3 through Code

Accessing the new Notification Settings in Android 4.3 through Code

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

How to&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"));

Answer:

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