【问题标题】:Send Intent with Extras From ADB over TCPIP to Android Device [duplicate]通过 TCPIP 从 ADB 向 Android 设备发送带有 Extras 的 Intent [重复]
【发布时间】:2018-06-07 18:52:14
【问题描述】:

我已经使用

成功地向我的 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"

我发现 post on SO 有几乎相同的问题,但是当我实施修复时,它仍然没有调用 SyncReceiver 的 OnReceive 事件

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

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

【问题讨论】:

  • 首先启动 shell adb -s <ip_address> shell 然后运行你的 am broadcast 命令
  • 你是个成功的人,谢谢大家
  • 再次感谢您,这将使整合到移动设备管理应用程序中变得更加容易。

标签: android android-intent adb android-broadcast android-broadcastreceiver


【解决方案1】:

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

原文:

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. 的回答 on this post

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-04
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    • 1970-01-01
    • 2019-05-09
    相关资源
    最近更新 更多