Cannot get the NotificationListenerService class to work

前端 未结 9 1864
梦如初夏
梦如初夏 2020-12-03 01:35

I have a android application that is trying to use the new NotificationListenerService class from api 18. I have created my own service class that inherits from this class a

9条回答
  •  难免孤独
    2020-12-03 02:19

    update: https://gist.github.com/xinghui/b2ffffd8cffe55c4b62f5d8846d5545bf9

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

    adb shell dumpsys notification

    check which service is living.

    com.android.server.notification.ManagedServices#rebindServices

    toggleNotificationListenerService() trigger system invoke this method.

提交回复
热议问题