Skip to content Skip to sidebar Skip to footer

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 >

Solution 1:

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

Solution 2:

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

import android.provider.Settings;

StringenabledAppList= Settings.Secure.getString(
        this.getContentResolver(), "enabled_notification_listeners");
booleantemp= enabledAppList.contains("youAppName");

Solution 3:

Keeping the status in a static variable from onBind() and onUnbind() worked for me.

publicbooleanonUnbind(Intent mIntent) {
    boolean mOnUnbind = super.onUnbind(mIntent);
    Common.isNotificationAccessEnabled = false;
    return mOnUnbind;
}

public IBinder onBind(Intent mIntent) {
    IBinder mIBinder = super.onBind(mIntent);
    Common.isNotificationAccessEnabled = true;
    return mIBinder;
}

Post a Comment for "Checking Android System Security Notification Access Setting Programmatically"