10

I am trying to send the BATTERY_CHANGED intent through the ADB shell. So far I only managed to send the intent with no information:

am broadcast -a android.intent.action.BATTERY_CHANGED

I created an app witch listens for this intent and here is what the system sends every few seconds:

#Intent;action=android.intent.action.BATTERY_CHANGED;launchFlags=0x60000010;i.icon-small=17302838;B.present=true;i.scale=100;i.level=100;S.technology=Li-ion;i.status=5;i.voltage=4155;i.invalid_charger=0;i.plugged=2;i.health=2;i.temperature=280;end

When I broadcast the intent my app shows this:

#Intent;action=android.intent.action.BATTERY_CHANGED;launchFlags=0x10;end

My question is how can I broadcast the intent through the adb shell with some of these properties/flags (like scale, status, plugged, etc.)?

Alex P.
  • 30,437
  • 17
  • 118
  • 169
Valyo
  • 103
  • 1
  • 1
  • 5

1 Answers1

14

The <INTENT> parameter format is the same for all am subcommands like start, startservice and broadcast.

It could be passed as a combination of separate parameters like -a <ACTION>, -c <CATEGORY>, -n <COMPONENT> and different -e <EXTRA> for different types of extras or as a single URI formatted string:

am broadcast "intent:#Intent;action=android.intent.action.BATTERY_CHANGED;i.status=5;i.voltage=4155;i.level=100;end"

Also make sure to properly escape the command when running outside of the interactive adb shell session:

adb shell "am broadcast 'intent:#Intent;action=android.intent.action.BATTERY_CHANGED;i.status=5;i.voltage=4155;i.level=100;end'"
Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • 12
    Thanks for the answer. It works perfectly. In the meantime I found another possible solution: `am broadcast -a android.intent.action.BATTERY_CHANGED --ez present false --ei state 2 --ei level 50` – Valyo Jul 22 '13 at 07:59
  • 1
    The answer her didn't work for me, but Valyo's comment here did work. Also, you must be in adb shell for this, so if you'r eon the commadnline, just prepend 'adb shell ' to the command here. – Stealth Rabbi Jan 15 '14 at 17:01
  • @Valyo comment did help but I had to change extras to am broadcast -a android.intent.action.BATTERY_CHANGED --ez present false --ei state 2 --ei level 50 – Igor Čordaš Mar 31 '15 at 13:12