我可以使用 adb shell 向我的应用程序发送命令吗
我想找到一种方法来创建可以使用 adb shell 或类似命令发送到我的应用程序的命令。这样我就可以对程序进行一些小的更改,而不必每次更改任何内容时都重新加载应用程序。
有没有办法打开 adb shell 并向正在运行的应用程序发送命令?
如果这是不可能的,那么向我的应用程序发送命令的可能方法是什么,以便我可以执行诸如(移动 UI 元素)或(从 URL 创建文件)或许多其他操作之类的操作......本质上我希望能够向我的应用程序发送字符串命令......
如果我可以使用命令行工具来做到这一点,那就太好了。否则什么是解决这个问题的好方法?
I want to find a way to create commands that I can send to my application using the adb shell or similar. This way I can do some small changes to my program without having to reload my application every time I change anything.
Is there a way to open the adb shell and send a command to a running application ?
If that is not possible, then what is a possible way to send commands to my application so I can do things like (Move the UI Elements) or (Create a file from a URL) or a number of other things.... Essentially I want to be able to send string commands to my application.....
If I can do that with the command line tools that would be sweet. otherwise What would be a good way to go about this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 adb shell 中,输入
am
。您可以启动活动和服务以及发送广播意图。没有参数将打印使用信息。如果您想从脚本调用它,您可以在主机上执行
adb shell am
。From an adb shell, type
am
. You can start activities and services as well as send broadcast intents. No arguments will print usage info.From the host machine you can do
adb shell am <command>
if you want to invoke this from scripts.adb shell am
选项可能是最干净/最好/最棒的选项,但是您可以在应用程序中使用一个线程来检查 SD 卡上是否存在特定文件。类似(请勿在没有严重修改的情况下使用此代码):那么您可以只使用
adb push
来编写命令文件。效率确实很低,但可以在紧要关头发挥作用。您还可以做更复杂的事情,例如创建本地 TCP/HTTP 服务器和使用 adb 端口转发,但这可能有点过头了。The
adb shell am
option is probably the cleanest/best/most awesome option, but you could have a Thread in your app checking for the presence of a specific file on the SD card. Something like (DON'T USE THIS CODE WITHOUT SERIOUS MODIFICATIONS):then you can just use
adb push
to write command files. Truly inefficient, but it can be made to work in a pinch. You can also do more complex things like creating local TCP/HTTP servers and using adb port forwarding, but that may just be overkill.