NotificationListenerService stopping and can't be restarted without a reboot

后端 未结 1 1625
心在旅途
心在旅途 2021-02-09 23:11

With android 4.4 I\'m finding that some users are having the notificationListenerService I\'ve implemented will just stop working. I\'ve actually seen this myself too.

I

相关标签:
1条回答
  • 2021-02-09 23:48

    This way can restart it, but it needs about 10s!

    private void toggleNotificationListenerService() {
            PackageManager pm = getPackageManager();
            pm.setComponentEnabledSetting(new ComponentName(this, com.xinghui.notificationlistenerservicedemo.NotificationListenerServiceImpl.class),
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    
            pm.setComponentEnabledSetting(new ComponentName(this, com.xinghui.notificationlistenerservicedemo.NotificationListenerServiceImpl.class),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    
        }
    

    Author:Hugo

    Link:https://www.zhihu.com/question/33540416/answer/113706620

    0 讨论(0)
提交回复
热议问题