我正试图将json数据作为额外数据发送到android广播上,我通过adb发送到设备。但看起来到达设备的数据并不像预期的那样。
我所执行的:

adb shell am broadcast -a com.test.android.ACTION_TEST_FEATURE -n com.test.android/.receivers.TestsReceiver -e "notify" '{"debug": false, "title": "Application update!"}'

我期望的额外数据:
{"debug": false, "title": "Application update!"}

我得到的额外数据:
"debug": false

如果我将{"debug": false "title": "Application update!"}作为额外数据发送,那么我将{"debug": false "title": "Application update!"}作为额外数据(注意缺少逗号)。因此,我认为这与bash的brace扩展有关,但关闭它并不能解决问题,并且无法转义brace或逗号。
有人知道我做错了什么吗?

最佳答案

你的解决办法帮了大忙!
它表明问题在于通过两个shell(主机加android)引用。空壳引用是一个可怕的停机坪,但这里有严重的额外奇怪。
在尝试“echo”命令之后,我发现adb shell的参数必须作为本地shell的单个参数引用,而json负载必须作为android shell的单个参数引用。
这是一个通用的解决方案(它不需要在json文本中使用\"!{字符):

adb shell "am broadcast -a com.test.android.ACTION_TEST_FEATURE -n com.test.android/.receivers.TestsReceiver -e notify '"'{"debug": false, "title": "Application update!"}'"'"

图案:}
内部对adb shell "am broadcast ... '"'JSON_TEXT'"'"标记在本地引用json_文本,而外部对则在远程引用它。那对外对又被引用了。

08-18 14:18
查看更多