How To Test BOOT_COMPLETED Broadcast Receiver In Emulator

On my Lollipop x86 emulator on Qemu, it required me to run as root:

adb shell su root am broadcast -a android.intent.action.BOOT_COMPLETED

Without root, the command fails: alarm manager does not send the broadcast:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED }
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=26595, uid=2000
    at android.os.Parcel.readException(Parcel.java:1684)
    at android.os.Parcel.readException(Parcel.java:1637)
    at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3537)
    at com.android.commands.am.Am.sendBroadcast(Am.java:772)
    at com.android.commands.am.Am.onRun(Am.java:404)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
    at com.android.commands.am.Am.main(Am.java:121)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)

Basically this is what you have to do to Emulate the Boot Complete in Android Emulater while is is running:Assuming you are a Windows User.The same applies for Linux

STEPS:On your Console type

  1. adb shell

  2. am broadcast -a android.intent.action.BOOT_COMPLETED

That is all folks. see the diagram below for a detailed illustration.

enter image description here

Happy Coding!


Some apps may misbehave if BOOT_COMPLETED is received twice, instead limit broadcast to your package only:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -p com.example.package

There is no Power Button in Emulator like Devices have,So

To stop an emulator instance, just close the emulator's window.

And To Start/Restart it Start from AVD Manager of Eclipse and Your BroadcastReceiver with BOOT_COMPLETE action will get called for sure

You can start AVD another way also, From CMD go to Tools of AndroidSDK and give this commmand E:\android-sdk-windows\tools>emulator -avd AVDNAMEHERE

To Send Broadcast from CMD you can use this Command.

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED


Read more about Android Emulator : Android Emulator and Using Emulator