首页 > 解决方案 > 通过 TCPIP 从 ADB 向 Android 设备发送带有 Extras 的 Intent

问题描述

我已经使用成功向我的 SyncReceiver(BroadcastReceiver) 发送了没有额外内容的意图

adb -s <ip_address> shell am broadcast -a com.istock.ALERT

但是,当我添加额外内容时,永远不会调用 SyncReceiver 的 OnReceive 事件,这是发送带有额外内容的意图的示例

adb -s <ip_address> shell am broadcast -a com.istock.ALERT --es title "Alert Title"

在 SO上发现了一个几乎相同问题的帖子,但是当我实施修复时,它仍然没有调用 SyncReceiver 的 OnReceive 事件

adb -s <ip_address> shell am broadcast -a com.istock.ALERT -n com.istock/.SyncReceiver --es title "Alert Title"

在这一点上,我只是不明白为什么我可以在没有通过 adb 发送的额外内容的情况下接收意图,并且无法接收带有额外内容的意图任何想法?

标签: androidandroid-intentadbandroid-broadcastandroid-broadcastreceiver

解决方案


我的问题是在一行中使用命令引起的,一旦我将命令分成两部分,它就可以按预期工作。

原来的:

adb -s <ip_address> shell am broadcast -a com.istock.ALERT --es title "Alert Title"

在职的:

adb -s <ip_address> shell

am broadcast -a com.istock.ALERT --es title "Alert Title"

终极解决方案:

我真的希望能够在一行中做到这一点(这将使移动设备管理(MDM)应用程序更容易工作。感谢@Alex P.对这篇文章的回答。

ADB 似乎破坏了封装在双引号 ("") 中的字符串,这是他建议的一种解决方法,只需使用单引号 ('')。

adb -s <ip_address> shell am broadcast -a com.istock.ALERT --es title 'Alert Title' --es message 'Alert Message'

推荐阅读