android - 通过 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 发送的额外内容的情况下接收意图,并且无法接收带有额外内容的意图任何想法?
解决方案
我的问题是在一行中使用命令引起的,一旦我将命令分成两部分,它就可以按预期工作。
原来的:
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'
推荐阅读
- python-3.x - 如何在不阻塞程序的情况下为命令制作计时器
- python - 在 Django 中创建新模型时在 s3 中动态放置文件
- svg - 定位svg文本
- ios - Interface Builder 约束问题
- c++ - 模板类中的模板成员特化
- angular - 您如何为 Angular http 请求(或其他任何东西)制作“请稍候”微调器?
- rest - Microsoft Graph Beta 创建调用 Calls.Initiate.All 未找到权限
- c# - 访问 Razor 页面中的属性
- python - 删除熊猫数据框中第一次出现条件之前的所有行
- makefile - 多次编译目标