50

I want to check the BROADCAST RECEIVER with Action BOOT_COMPLETED in the emulator.

Is there any way to check that broadcast receiver in emulator ? How can i restart emulator to check that receiver ? is there any direct command?

Thanks in advance.

Charles
  • 50,943
  • 13
  • 104
  • 142
Chirag
  • 56,621
  • 29
  • 151
  • 198
  • I tried using adb to send the broadcast and it did not work for me on Android O. I got a security exception. I had to reboot the emulator, which I actually did by holding down the power button icon and choosing reboot from the GUI. – Robert Wiebe Jul 07 '18 at 02:51

6 Answers6

59

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

SMR
  • 6,628
  • 2
  • 35
  • 56
MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • 13
    ```adb shell am broadcast -a android.intent.action.BOOT_COMPLETED``` is fully sufficient for a device reboot. – drindt Jun 10 '15 at 08:31
  • 9
    Unfortunately, sending that broadcast causes my Nexus 5 to *really* reboot instead of just broadcasting that message. As a result, the debugger is disconnected. /sigh sending broadcasts like this should accessible to the dev in an easier-to-use manner :-( :-( – Someone Somewhere Jul 06 '15 at 23:40
  • 6
    Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400000 pkg=com.myapp.package } Security exception: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=11148, uid=2000 – akshay bhange May 22 '20 at 15:35
  • how to get adb in my path? I installed android studio 4 and it's not found anywhere but except eclipse logs that it is running that command. – Dean Hiller Aug 07 '20 at 01:28
  • 1
    @akshaybhange use `adb root` before it – FreePhoenix888 Jul 03 '22 at 17:33
44

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!

Fred Ondieki
  • 2,314
  • 25
  • 23
39

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
ejboy
  • 4,081
  • 5
  • 30
  • 32
  • 7
    For a strange fun, I copied the command without adding my package name, hoping that I could see some apps "really" misbehaving. It killed almost every other apps and somewhat rebooted the device. Worth it... :) – C-- Aug 01 '15 at 17:54
  • The -p option errors for me and http://developer.android.com/tools/help/shell.html#IntentSpec doesn't mention it? – matt snider Jan 04 '16 at 20:38
  • 1
    Not all Android versions supported -p, you can try -n package_name/class_name – ejboy Jan 07 '16 at 23:11
8

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)
Peter Chaula
  • 3,456
  • 2
  • 28
  • 32
2

If you're using flavors, be careful with the . component name shortcut notation.

Example

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.companyname.develop/com.companyname.notification.RescheduleLocalNotificationsAtBootReceiver
Julio Rodrigues
  • 3,373
  • 3
  • 24
  • 33
-1

To restart the emulator just open your command line and switch to folder where your adb is (if not in system path) and enter:

adb restart

(then you can abort the command with Strg - C to get cmd line back)

Fabian
  • 2,693
  • 2
  • 21
  • 33