I'm currently developing an app for Android that uses the NotificationListenerService
, which requires that the user will enable notification access for my app under Setting -> Security -> Notification Access
.
My question is that can I redirect the user to this place so they will enable it? So far I only managed to direct them to Setting -> Security
window.
Also, is it possible to first check if the user enabled notification access for my app already and only then redirect them?
The serious vulnerability is Android's “Notification Listening Service,” which can be enabled by a permission a newly installed app tricks users into granting, and which will allow the app to intercept and manipulate incoming messages.
Some features have to be stripped off to make the software perform well on such hardware. The "Notification Access" permission however has nothing to do with you receiving notifications. It's a permission for apps to "read" your notifications, not "send" them.
You can open the NotificationAccessSettingsActivity
by using the following Intent
, but I'm not sure about checking to see if they've already enabled your app.
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
Alternatively, for API 22+:
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
Many Thanks to @adneal and @Waboodoo. I am posting this for an complete answer
Check permission granted or not using this method
private boolean isNotificationServiceRunning() {
ContentResolver contentResolver = getContentResolver();
String enabledNotificationListeners =
Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
String packageName = getPackageName();
return enabledNotificationListeners != null && enabledNotificationListeners.contains(packageName);
}
Then show settings activity, if necessary
boolean isNotificationServiceRunning = isNotificationServiceRunning();
if(!isNotificationServiceRunning){
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With