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);
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
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");
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