How to broadcast intent with extras through ADB shell?

旧巷老猫 提交于 2019-11-27 02:47:40

问题


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


回答1:


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"


来源:https://stackoverflow.com/questions/17717728/how-to-broadcast-intent-with-extras-through-adb-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!