Search code examples
androiddebuggingandroid-intentbroadcastreceiveradb

Debug android.intent.action.BOOT_COMPLETED


I want to debug a BroadcastReceiver which should start its onReceive method when the action android.intent.action.BOOT_COMPLETED is triggered. I have read several sources like

but the all came with the solution to run

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

or

./adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c <CATEGORY> -n <PACKAGE_NAME>/<CLASS>

The first one restarts the device or the emulator but the debugger gets disconnected. The second one does not work. When I enter

./adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME mypackage/.BootReceiver

the message is

Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED cat=[android.intent.category.HOME] cmp=mypackage/.BootReceiver }
Broadcast completed: result=0

and nothing happens. So my question is:

Is there a way to debug a BroadcastReceiver which gets triggered when android.intent.action.BOOT_COMPLETED occurs?

I am using a Nexus 4 as a device and also a Nexus 4 as an emulator. My IDE is android studio with version 1.2.2.


Solution

  • Use sendBroadcast() to send broadcast manually

    Add some action ("NameofAction") to the receiver in the manifest and then manually use sendBroadcast(new Intent("NameofAction")) with the name you specified in the receiver element in the manifest.

    and in onReceive() check for the action ("NameofAction").