问题描述
我正在尝试通过ADB Shell发送 BATTERY_CHANGED
意图。到目前为止,我只发送了没有任何信息的意图:
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
我的问题是如何通过 adb shell
广播意图中的某些属性/ flags(例如刻度,状态,已插入等)?
My question is how can I broadcast the intent through the adb shell
with some of these properties/flags (like scale, status, plugged, etc.)?
推荐答案
< INTENT>
pa所有 am
子命令的参数格式都相同,例如 start
, startservice
和广播
。
The <INTENT>
parameter format is the same for all am
subcommands like start
, startservice
and broadcast
.
它可以作为单独参数的组合(如)传递-a< ACTION>
, -c< CATEGORY>
, -n< COMPONENT>
和不同的 -e< EXTRA>
用于不同类型的附加功能,或作为单个 URI
格式的字符串:
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"
还请确保在以下情况下正确转义该命令在交互式 adb shell
会话之外运行:
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'"
这篇关于如何通过ADB Shell广播带有附加内容的意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!