Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

android - Enable/Disable “enabled_notification_listeners” Programmatically?

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?

question from:https://stackoverflow.com/questions/65842290/enable-disable-enabled-notification-listeners-programmatically

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...