4

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.

Community
  • 1
  • 1
LucasMoody
  • 403
  • 4
  • 10
  • If nothing else you can move to printf debugging- Write statements to log and see what the values of variables are when you run it, rather than stepping through via debugger. – Gabe Sechan Jul 10 '15 at 00:10

1 Answers1

2

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").

Syed
  • 287
  • 1
  • 3
  • 15
  • Manually sending a Broadcast for android.intent.action.BOOT_COMPLETED is not allowed. – LucasMoody Jul 11 '15 at 14:18
  • I was telling create some action manually "NameofAction" for testing purpose and add it to BOOT_COMPLETED receiver and fire it manually. – Syed Jul 13 '15 at 06:19