Search code examples
androidservicealarmmanagerandroid-reboot

Android After Reboot Broadcast Receiver is not running


I used this permission:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

and the receiver is:

<receiver android:name=".auth.NotificationBroadcast" android:enabled="true" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

and receiver in code is:

@Override
    public void onReceive(Context context, Intent intent) {

        System.out.println("BroadcastReceiverBroadcast--------------------ReceiverBroadcastReceiverBroadcastReceiver----------------BroadcastReceiver");

        if (intent != null) {
            String action = intent.getAction();

        switch (action) {
            case Intent.ACTION_BOOT_COMPLETED:
                System.out.println("Called on REBOOT");
                // start a new service and repeat using alarm manager

                break;
            default:
                break;
        }
    }
}

After reboot it's still not getting called in lollipop, but on marshmallow it's running.


Solution

  • try to put this line in your receiver's intent-filter.

    <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
    

    If your application is installed on the SD card, you should register this to get the android.intent.action.BOOT_COMPLETED event.

    Updated: Since your app is using alarm service, it should not be installed on external storage. Reference: http://developer.android.com/guide/topics/data/install-location.html