use adb shell dumpsys notification The picture was found from web to explain my question. I have created a class which extends NotificationListenerService,but sometimes it doesn't work(I mean it can not receive notifications and do something) even though I give it the access on setting.I heard that mybe the android System closed the service and only add function:toggleNotificationListenerService.
public static void toggleNotificationListenerService(Context context) {
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(
new ComponentName(context, com.zhenglei.launcher_test.qianghongbao.NotificationService.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(
new ComponentName(context, com.zhenglei.launcher_test.qianghongbao.NotificationService.class),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
But when/where can I use this function, I try to use it in 'onResume'...but not satisfied.I most want to ask is:How to judge the service was closed by system(the Permission is already opening),can someone give me a function? please forgive my bad English ^_^