首页 > 解决方案 > 以编程方式启用/禁用“enabled_notification_listeners”?

问题描述

在我的应用程序中,我启用了“enabled_notification_listeners”,它在除一种情况外的所有情况下都有效。

如果我们第一次运行应用程序,我检查它是否启用,如果没有,则将用户重定向到通知访问设置,如果我升级应用程序或从 android studio 运行应用程序,我正在检查它是启用与否它给了我它已启用但当通知到来时我没有收到任何回调。

如果我手动禁用它并启用它,它就会开始工作。

那么有什么方法可以通过编程方式禁用它?

这是我打开设置页面的方式:

startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS));

我如何检查它是启用还是禁用:

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

我们可以以编程方式更改其状态吗?

标签: androidpush-notificationandroid-notificationsnotification-listener

解决方案


推荐阅读