At the moment I ask for the permission to use the Notification Access (Notification Listener Service) in the following way:
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
This does work, but the user has to choose my app from a list of apps.
To improve the usability, I'd like it to look more like this
Does anyone know how to filter it properly?
For the usage access settings I use the following Code:
Intent myIntent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS, Uri.parse("package:" + getPackageName()));
startActivity(myIntent);
Sadly, this does not work for notification access settings. Error:
No Activity found to handle Intent { act=android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS dat=package:notificationmanager }
Found a solution:
ComponentName componentName = new ComponentName(getPackageName(), YOUR_LISTENER_CLASS.class.getName());
Intent notificationAccessSettings =
new Intent(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS));
notificationAccessSettings.putExtra(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, componentName.flattenToString());
startActivity(notificationAccessSettings);
This was only introduced in API Version 30, and I don't know a way (or if it is even possible) for earlier versions.