Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to Notification Access Settings

Tags:

android

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?

like image 964
Gershon Papi Avatar asked Mar 26 '14 14:03

Gershon Papi


People also ask

Is giving notification access safe?

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.

Why do you need notification access permission?

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.


2 Answers

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));
like image 94
adneal Avatar answered Sep 18 '22 07:09

adneal


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));
}
like image 32
mili Avatar answered Sep 18 '22 07:09

mili