2013-11-25 32 views
5

使用android 4.4我發現有些用戶正在使用notificationListenerService,我已經實現了這個功能就會停止工作。我也親自看過這個。NotificationListenerService停止並且不能在沒有重新啓動的情況下重新啓動

我從來沒有設法捕獲它發生的時間周圍的任何logcats,但即使進入通知訪問部分並關閉和返回通知訪問沒有幫助。

有什麼可以導致這種情況發生。我不確定我的應用程序是否崩潰並導致此問題,但即使如此,似乎重新啓動偵聽程序的唯一方法是重新啓動手機。是否有另一種方式來啓動我的應用程序從偵聽器服務接收通知?

我還會在更新應用程序的版本時收到用戶遇到此問題的報告。

我試着把日誌放入onCreate/onDestroy方法來查看停止時是否有任何東西被記錄下來,但onUnbind,onDestroy被調用,但沒有爲這些方法中的任何一個輸入,所以我猜他們沒有得到一旦它停止,就會被調用。

編輯: 我捕捉到的bug報告後,這事發生和日誌的有趣的部分看起來是:

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 

因此,它看起來像有一個警告,那麼這是怎麼回事進入停止服務並重新啓動它(它與我的應用程序,也發生在其他應用程序我已經安裝了使用通知接入看着兩塊停止)

真的不知道我能做些什麼來阻止這種停止

回答

1

這樣,才能重新啓動它,但它需要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

相關問題