从 PC 向 Android 手机发送命令 - 通过物理连接(USB、串行等) [英] Sending commands from a PC to an Android phone - via physical connection (USB, Serial, etc)

查看:172
本文介绍了从 PC 向 Android 手机发送命令 - 通过物理连接(USB、串行等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个项目,以在 Android 手机上从 PC 上自动执行一些任务(例如播放歌曲、播放视频、接收蓝牙数据等).

I'm working on a project to automate some tasks (such as play a song, play a video, receive bluetooth data, etc) on an Android phone from a PC.

基本上,PC 会向手机发送通知程序,然后手机上的应用程序或其他东西会处理通知程序并执行某些操作".与此相反:http://code.google.com/p/android-notifier/

Basically the PC will send a notifier to the phone and an app or something on the phone would then process the notifier and do 'something'. The opposite of this really: http://code.google.com/p/android-notifier/

我看到了一些示例,展示了如何通过网络连接向 Android 侦听器应用或服务发送命令,但在这种情况下,我更希望通过物理连接进行传输.

I've seen some examples showing how to send commands to an Android listener app or service via a network connection, but in this case, I would much rather the transmission be over a physical connection.

USB理想情况下,我希望通过 USB 端口进行连接.但我在网上看到一些帖子表明 SDK 本身并不支持这一点.(Android 应用程序,与插入的设备通信USB 端口).

USB Ideally, I'd like the connection to be via the USB port. But I've seen some posts online that suggest that the SDK does not natively support this. (Android apps, communicating with a device plugged in the USB port).

通过 USB 串行传输我还看到一些网站展示了如何使用分线盒执行双向串行通信,但仅限于 G1.新手机可以做到这一点吗?

Serial over USB I've also seen some sites that show how to use a breakoutbox to perform bi-directional serial communication, but only with the G1. Is this possible with newer phones?

电话我对任何新手机都持开放态度.我目前正在看 Galaxy S,因为它通过耳机插孔输出视频.如果需要,我愿意生根.

The Phone I'm open to really any newish phone. I'm currently looking at the Galaxy S, because it has the video out through the headphone jack. I'm open to rooting if need be.

推荐答案

在您的应用中实现 HTTP 服务器,然后将手机置于 USB Tether 模式.这将在您的手机和 PC 之间创建一个本地网络.然后,您应该能够使用手机的 ip 发送 HTTP 请求或创建 websocket.

Implement a HTTP server in your app, then put your phone in USB Tether mode. This will create a local network between your phone and your PC. You should then be able to send HTTP request or create websockets using the phone's ip.

我对其进行了测试,它可以工作,请参阅 这里

EDIT : I tested it, and it works, see here

这篇关于从 PC 向 Android 手机发送命令 - 通过物理连接(USB、串行等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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