Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotificationListenerService stopping and can't be restarted without a reboot

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.

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

like image 434
Andrew Avatar asked Nov 12 '22 17:11

Andrew


1 Answers

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

like image 93
user3659153 Avatar answered Nov 15 '22 06:11

user3659153