ADB can be used to send broadcast intent by for example:
adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"
where: -a
is the action and -es
is the extra string. My thought is that the action parameter is necessary, since it is used by the intent receiver to receive the intent using (intent filter). However, I noticed that we can send intent without specifying the action for example:
adb shell am broadcast -n com.google.android.deskclock/com.android.deskclock/com.android.deskclock.AlarmInitReceiver
Why this is possible? Isn't an empty intent? and any applications of such thing?
Isn't an empty intent?
No. -n
creates an explicit Intent
, one that identifies the application ID (com.google.android.deskclock
) and the component (com.android.deskclock.AlarmInitReceiver
). Using an explicit Intent
directly delivers the Intent
to the designated component; in your case, via a broadcast.
and any applications of such thing?
Explicit Intents
are used widely in Android, perhaps even more commonly than are implicit Intents
. Examples include:
Tapping on a home screen launcher icon (startActivity()
with an explicit Intent
)
JobService
and other specialized service classes (bindService()
with an explicit Intent
)
ACTION_MY_PACKAGE_REPLACED
(sendBroadcast()
with an explicit Intent
)