Enable/Disable “enabled_notification_listeners” Programmatically?

439 views Asked by At

In my app, I am enabling "enabled_notification_listeners" it is working in all cases except one case.

If we run the app the first time I am checking if is it enables or not if not then redirecting a user to the setting of notification access and if I upgrade the app or run the app from the android studio and I am checking that it is enabled or not it gives me it is enabled but when a notification comes I didn't receive any callbacks.

If I manually disable it and enable it, it starts working.

So is there any way that we can disable it programmatically?

Here is how I am opening the setting page:

startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS));

How I am checking if is it enables or disables:

boolean hasNotificationAccess()
    {
        ContentResolver contentResolver = this.getContentResolver();
        String enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
        String packageName = this.getPackageName();

        return !(enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName));
    } 

Can we change its status programmatically?

0

There are 0 answers