I’m working on a background service that is going to be triggered by the alarm manager. I’ve set everything up for my broadcast receiver, though I’d like to test it without having to write a bunch of Java code. After looking around a bit I’ve come across this am tool that appears to do what I need, though I don’t know how to create a specific broadcast intent.
Let’s say my BroadcastReceiver is com.foo.receiver.NiftyReceiver and I have it in my manifest file as <receiver android:name=”.receiver.NiftyReceiver” />
The documentation is a bit lacking on how to use the tool, but after a bit of confusion I’ve finally figured out how to get it working.
am broadcast -n com.foo/com.foo.receiver.NiftyReceiver
Note, you need to add the android:exported=”true” to your <receiver> otherwise android will spew this nifty little error message on you:
W/ActivityManager(16908): Permission denied: checkComponentPermission() reqUid=10066
W/ActivityManager(16908): Permission Denial: broadcasting Intent { cmp=com.foo/.receiver.NiftyReceiver } from null (pid=1411, uid=2000) requires null due to receiver com.foo/com.foo.receiver.NiftyReceiver
I’m pretty sure this isn’t anything new, but I personally found tools like am aren’t really documented that well. Hopefully this will save someone else a bit of time in the future!