Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Android System Security Notification Access setting programmatically

Is there a way to check whether the below setting is enabled or disabled programmatically in Android?

Settings > Security > Device Administration > Notification Access > My App 

Currently I'm invoking the settings dialog from my app through the below method but if the settings are already enabled then I dont want to present this settings.

Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);
like image 942
AndroidDev Avatar asked Jun 10 '14 15:06

AndroidDev


2 Answers

Make it simple

  if (Settings.Secure.getString(this.getContentResolver(),"enabled_notification_listeners").contains(getApplicationContext().getPackageName())) 
    {
        //service is enabled do something
    } else {
        //service is not enabled try to enabled by calling...
       getApplicationContext().startActivity(new Intent(
            "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
    }

'else' part is optional according your question

like image 192
Ashish Sahu Avatar answered Nov 16 '22 19:11

Ashish Sahu


To judge whether Android Settings Notification contains your app or not, you should do:

import android.provider.Settings;

String enabledAppList = Settings.Secure.getString(
        this.getContentResolver(), "enabled_notification_listeners");
boolean temp = enabledAppList.contains("youAppName");
like image 27
li2 Avatar answered Nov 16 '22 21:11

li2