How to reboot emulator to test ACTION_BOOT_COMPLETED?
Asked Answered
H

7

33

Well, I have searched a lot. People say that I need to close the window of emulator to close it. However, I need to reboot the emulator to catch ACTION_BOOT_COMPLETED by my BroadcastReceiver.

How can I do that?

Heaton answered 11/2, 2012 at 16:6 Comment(0)
E
36

You can use the following command from adb:

adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME

for example:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name

Note that class name and package names need to be as defined in the Manifest.

This will generate the Intent you want , directed only to the component you want (otherwise you system will go crazy with BOOT_COMPLETED sent...)

Expend answered 13/2, 2012 at 8:6 Comment(2)
Thanks. The code looks great. Currently I don't have time to test. But I found out that without using snapshot, the emulator is a lot faster in booting, and closing :-) I like it!Heaton
when I execute that from Android Studio terminal (emulator with Android 7.1.1 is running), I get the message java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=7432, uid=2000Keitloa
G
31

Or another way (also from the command line):

adb shell stop
adb shell start
Guadiana answered 11/2, 2012 at 16:18 Comment(3)
yeah i was able to verify my onReceive was called listening for BOOT_COMPLETED using this way. However, the break point I had didn't hit because the debugger became detached, but I saw my log statement in DDMS.Sennight
in Android studio terminal, I get the message stop: must be root whilst Android 7.1.1 emulator is runningKeitloa
@SomeoneSomewhere I accidentally mashed adb -e root in my terminal and it printed restarting adbd as root. After that I was able to run these commands.Mucoviscidosis
K
9

First, make sure that USB Debugging is enabled from within the emulator:

click:

  • the Home icon
  • Menu icon
  • 'Settings'
  • 'Applications'
  • 'Development'
  • make sure that the box next to 'USB debugging' contains a check mark

from a command-line:

adb -e reboot

EDIT:

This definitely doesn't work... very strange. I tested it and could not make the emulator reboot. It just hangs.

Kendalkendall answered 11/2, 2012 at 16:13 Comment(1)
Excuse me, could you tell me if you run adb reboot successfully? I run it for 45 mins, the process emulator-arm keeps using 50% of CPU. It's not responding :-(Heaton
B
8

To emulate a broadcast action, you can connect via adb to the emulator/device and open a shell:

adb shell

Then, you can broadcast the action you want to test:

am broadcast -a android.intent.action.BOOT_COMPLETED

Please note that, in the latest Android versions, broadcasting the *android.intent.action.BOOT_COMPLETED* action will actually reboot your emulator/device.

Borszcz answered 27/9, 2013 at 16:24 Comment(1)
on Android emulator 7.1.1, I get the following message on Terminal: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=6832, uid=2000Keitloa
V
0

While using tubemate on android tab, I was not successful in downloading video with the error:host interupped etc. I used the following commands:

adb shell stop
adb shell start

and the application started downloading videos.

Vance answered 8/7, 2014 at 14:34 Comment(0)
P
-3

emulators have on/off button - just click it

Psychotic answered 11/2, 2012 at 16:10 Comment(2)
When I click the power button (and hold for 2 or 3 secs), it acts as like real device: it shows me menu of Silent mode/ Airplane mode/ Power off. I click Power off, but then I can't turn it on :-( . It keeps showing "Shutting down..."Heaton
holding power button helps (current latest emulator version)Faydra
G
-3

and another way:

If you start your emulator, and select the "wipe user data" checkbox, you will also receive that notification when boot is completed.

Guadiana answered 11/2, 2012 at 16:19 Comment(3)
But if I wipe data, the app that I installed will be erased :-)Heaton
Have you tested that Wipe Use Data does in fact erase installed apps? I believe that it will wipe data (preferences, cache, etc) that have been stored by apps, but not the apps themselves...Kendalkendall
@DavidDraughn, Sorry for late reply... But it erases all and returns original.Heaton

© 2022 - 2024 — McMap. All rights reserved.