NotificationListenerService正在停止,并且无法重新启动而无法重新启动 [英] NotificationListenerService stopping and can't be restarted without a reboot

查看:325
本文介绍了NotificationListenerService正在停止,并且无法重新启动而无法重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android 4.4中,我发现有些用户拥有已实现的NotificationListenerService会停止工作.我实际上也亲自看过这个.

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've never managed to capture any logcats around the time of it happening, but even going into the notification access section and switching off and back on the notification access doesn't help.

是否有可能导致这种情况发生的原因.我不确定我的应用是否崩溃并导致了这种情况,但是即使如此,似乎重启监听器的唯一方法就是重启手机.还有另一种方法来启动我的应用程序以接收来自侦听器服务的通知吗?

Is there something that can cause this to happen. I'm not sure if my app is crashing and causing this, but even if so it seems the only way to restart the listener is to reboot the phone. Is there another way to start my app receiving notifications from the listener service?

我还收到有关用户在更新应用程序版本时遇到此问题的报告.

I also get reports of users getting this issue when updating the version of the app.

我尝试将日志放入onCreate/onDestroy方法中,以查看停止时是否记录了任何内容,但是调用了onUnbind,onDestroy,但是这两种方法均未输入任何内容,因此我想它们没有被调用一旦停止.

I've tried putting logs into the onCreate/onDestroy method to see if anything gets logged when it stops, but the onUnbind, onDestroy are called, but nothing is entered for either of these methods so I guess they are not getting called once it's stopped.

修改: 发生这种情况后,我捕获了一个错误报告,日志中有趣的部分看起来是:

edit: I captured a bug report after this had happened and the interesting part of the log looks to be:

12-30 15:33:58.731 16194 16194 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendOrderedBroadcast:1192 android.app.ContextImpl.sendOrderedBroadcast:1183 android.content.ContextWrapper.sendOrderedBroadcast:390 com.android.settings.applications.ProcessStatsDetail.checkForceStop:314 com.android.settings.applications.ProcessStatsDetail.onResume:108 
12-30 15:33:58.741   780   780 V NotificationService: disabling notification listener   for user 0: ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.NotificationListener}
12-30 15:33:58.741   780   780 V NotificationService: disabling notification listener for user 0: ComponentInfo{lovetere.flashme/lovetere.flashme.accessibilityservice.ServicePostKitKat}
12-30 15:33:58.741   780   780 V NotificationService: enabling notification listener for user 0: ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.NotificationListener}
12-30 15:33:58.741   780   780 V NotificationService: enabling notification listener for user 0: ComponentInfo{lovetere.flashme/lovetere.flashme.accessibilityservice.ServicePostKitKat}
12-30 15:33:58.751  1171  1171 D MyApp:NotificationListener: [NotificationListener] onDestroy

因此,似乎有一个警告,即将停止服务并重新启动它(我的应用程序以及我安装的另一个使用通知访问权的应用程序(正在查看正在停止的两个应用程序)都发生了这种情况)

So it looks like there's a warning that's then going into stopping the service and restarting it (it happens with my app and also the other app I've installed that uses the notification access looking at two that are stopping)

真的不确定我能做些什么来阻止这种停止

Really not sure what I can do to stop this stopping

推荐答案

这种方式可以重新启动它,但大约需要10秒钟!

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

    }

作者:雨果

链接: https://www.zhihu.com/question/33540416/answer/113706620

这篇关于NotificationListenerService正在停止,并且无法重新启动而无法重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆