我怎么能发送消息来回亚行外壳和Android应用程序之间? [英] How can I send messages back and forth between ADB shell and an Android app?

查看:230
本文介绍了我怎么能发送消息来回亚行外壳和Android应用程序之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个答案或在过去的3天,还没有找到一个工程。我试图写一个Android应用程序,可以从亚行与自定义命令进行控制。有反正我可以一个应用程序和亚行外壳之间字符串发送回一个来回?

I've been looking for an answer or the past 3 days, and haven't yet found one that works. I'm trying to write an Android app that can be controlled from ADB with custom commands. Is there anyway I can send strings back an forth between an app and an ADB shell?

在此先感谢,以及对不起我小白qustion。

Thanks in advance, and sorry for my noob qustion.

推荐答案

当然,也有几种方法可以做到这一点。

Sure, there are several ways to do this.


  • 您可以使用UNIX域套接字,并同时从Android应用程序和命令行可执行文件,你将建立由滥用NDK打开它,推到一个不同版本的不同位置,在设备上(/数据/地方,/ sqlite_stmt_journals等),并运行。编辑:在最近的Andr​​oid版本也有可能不会是这样写/可执行文件的目录。您可能必须有应用程序本身编写的可执行文件到其私有目录,并设置全局读并在其上执行权限。进一步编辑:亚行可以转发Unix套接字,太

  • You could use a unix domain socket, and open it from both the android app and from a command line executable you would build by abusing the ndk, push to a version-dependent location on the device (/data/local, /sqlite_stmt_journals, etc) and run. in more recent android versions there may not be such writable/executable directories. You may have to have the app itself write the executable out to its private directory and set global read and execute permissions on it. Further adb can forward unix sockets, too.

,只是现在你有前冲了亚行端口选项(提供的Andr​​oid应用程序是'服务器'端)与互联网插座同样的事情,以便从流程开发机器上运行的通信直接与Android应用程序,而无需通过亚行的shell传递数据。除非宣布网络权限是反感的(应该不是让你的PC端应用驱动亚行较少关注),这或许是会坚持最接近官方的能力,并有至少Android版本依赖的方式。它也可以被平凡适于在无线通信的

Same thing with an internet socket, only now you have the option of setting up an adb port forward (provided the android app is the 'server' end) so as to communicate from a process running on your development machine directly with the android app, without passing data through the adb shell. Unless declaring internet permission is objectionable (it should be less of a concern than letting your PC-side app "drive" adb) this is probably the method that would stick closest to "official" capabilities and have the least android version dependence. It also can be trivially adapted to communicating over wifi.

您可以使用一对的FIFO的读写和shell命令阅读这些邮件(便携性,在应用程序的专用存储创建它们,但让他们的世界可读/写)

You could use a pair of fifos and write and read them with shell commands (for portability, create them in the app's private storage but make them world readable/writeable)

您可以用PTY玩一些游戏

you may be able to play some games with a pty

你可以,我想使用文件作为邮箱

you could I suppose use files as mailboxes

您可以用AM命令发送意图(至少启动Android应用程序非常有用,如果有点低效通信)

you can use the 'am' command to send Intents (useful at least to start up the android app, if a bit inefficient for the communication)

这篇关于我怎么能发送消息来回亚行外壳和Android应用程序之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆