Skip to content Skip to sidebar Skip to footer

Notificationlistenerservice Not Working After Device Boot_complete

I am working with NotificationListnerService it is working fine after some time it can not work and specially after device is boot it is not starting i have given all permissions w

Solution 1:

I have found solution for this by just adding some lines of code

 @Override
public void onListenerConnected() {
    super.onListenerConnected();
    Log.i("tag","Listner conneted");
    tryReconnectService();
}


 public void tryReconnectService() {
    toggleNotificationListenerService();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        ComponentName componentName =
                new ComponentName(getApplicationContext(), Whatsapp_recorder.class);

        //It say to Notification Manager RE-BIND your service to listen notifications again inmediatelly!
        requestRebind(componentName);
    }
}

/**
 * Try deactivate/activate your component service
 */
private void toggleNotificationListenerService() {
    PackageManager pm = getPackageManager();
    pm.setComponentEnabledSetting(new ComponentName(this, Whatsapp_recorder.class),
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(new ComponentName(this, Whatsapp_recorder.class),
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}

Post a Comment for "Notificationlistenerservice Not Working After Device Boot_complete"