BroadcastReceiver not receiving BOOT_COMPLETED

I'm posting this in the hope that it will be helpful to someone who has tried everything but still cannot get it to run on boot after installation or it used to work before and doesn't work anymore.

So assuming you have added the permission:

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

And registered your receiver:

<receiver android:name="com.example.startuptest.StartUpBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

And coded your BroadcastReceiver:

public class StartUpBootReceiver extends BroadcastReceiver {

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

        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Log.d("startuptest", "StartUpBootReceiver BOOT_COMPLETED");
            ...
        }
    }
}

Starting with Android 3.1 all applications, upon installation, are placed in a "stopped" state.(This is the same state that the application ends up in after the user force-stops the app from the Settings application.)

Android stopped state

While in "stopped" state, the application will not run for any reason, except by a manual launch of an activity. (Meaning no BroadcastRecevier(ACTION_PACKAGE_INSTALLED, BOOT_COMPLETED etc. will be invoked, regardless of the event for which they have registered, until the user runs the app manually.)

This is a design decision by Google to prevent malware apps. Google has advocated that users should launch an activity from the launcher first, before that application can do much. Preventing BOOT_COMPLETED from being delivered until the activity is launched is a logical consequence of that argument.

Once a user runs any activity in your app once, you will receive the BOOT_COMPLETED broadcast after all future boots.

More details about this:
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
http://commonsware.com/blog/2011/07/05/boot-completed-regression.html
http://devmaze.wordpress.com/2011/12/05/activating-applications/


If your app installed on external storage(SD card), you will never receive Boot Complete action. So you have to specify android:installLocation="internalOnly" in the manifest tag.


You can emulate all broadcast actions by connecting via adb to the device and open a device shell.

Here we go:

  • open console/terminal and navigating to /platform-tools
  • type adb shell or on linux/mac ./adb shell
  • in the shell type am broadcast -a android.intent.action.BOOT_COMPLETED or whatever action you want to fire

There are a bunch of nice commands coming with adb or the adb shell. Just try it

Regards Flo

edit: oh damn, i wanted this answer as an answer on the "had to turn phone on/off every time". sorry folks