Android 应用程序,与插入 USB 端口的设备通信

发布于 2024-09-25 12:51:31 字数 586 浏览 0 评论 0原文

我正在考虑一个 Android 应用程序(可能还有一个附带的物理设备),并且我正在尝试弄清楚这是否可行。

1) 假设我将 Android 设备连接到 PC 上。安装在PC上的应用程序是否可以与手机上运行的应用程序进行通信?我只需要一种非常简单的数据交换,甚至可以是单向的(只需将数据从手机推送到PC上的监听应用程序,只要手机需要,我不需要任何从PC发送到手机的数据)。

当我插入时,手机给了我 4 个选项(充电、磁盘驱动器、HTC 同步、网络共享),这让我觉得这是不可行的,但仍然值得一试。

2) PC 上的应用程序是否可以通过任何其他方式与手机上的应用程序对话? (Wi-Fi、蓝牙等)。我猜 Wi-Fi 上不行,因为双方都没有对方的 IP(我希望这能正常工作,而不必一直手动输入 IP)。

3)如果我制作一个插入手机底部小USB端口的设备(假设这是一个可以做任何事情的神奇设备,只要它可行,我不太关心这些细节)。我可以让 Android 应用程序与该设备通信吗?

4) 任何其他让手机与我制作的“设备”或 PC 中的应用程序对话的想法都非常受欢迎。 “通过网络”可能是一种选择(尽管我相信必须有一个我作为中间人拥有的中央服务器)。但我更喜欢两个设备之间直接进行通信。

I'm thinking about an Android app (with possibly an accompanying physical device), and I'm trying to figure out whether this is something that's feasible.

1) Let's say I plug my Android to my PC. Would it be possible for an app installed on the PC to communicate with an app running in the cell phone? I just need a very simplistic data exchange, it can even be one-way (just data pushed from the cell phone to the listening app on the PC, whenever the cell phone wants, I don't need any data sent from PC to phone).

When I plug it in, the phone gives me 4 options (charge, disk drive, HTC sync, tethering), which makes me think this is not doable, but still worth the shot.

2) Would it be possible for an app on the PC to talk to an app on the phone through any other way? (Wi-fi, bluetooth, etc). I'm guessing no on wi-fi since neither party has the other's IP (and I want this to kinda just work, not having to input IPs manually all the time).

3) If I make a device that's plugged to the little USB port at the bottom of the phone (and let's say this is a magical device that can do anything, I don't quite care about those details as long as it's doable). Can I have an Android app talk to that device?

4) Any other ideas to make the phone talk to a "device" that I make, or to an app in the PC are more than welcome. Going "through the web" could be an option (although there'd have to be a central server that I own as a middle man, I believe). But I'd prefer if the communication was direct between the two devices.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寂寞陪衬 2024-10-02 12:51:31

The world has changed since this question was asked, and the answer is now the Android Open Accessory Development Kit. It won't solve the problem for existing USB devices, but it makes it possible to create new devices that can use an Android device's USB connection.

夜还是长夜 2024-10-02 12:51:31

Android 设备和 PC 之间的通信可以通过另一种方式实现。

通过 USB 通过 ADB 连接。

  1. 端口转发。
  2. 服务器套接字JAVA程序。
  3. 客户端套接字 Android 应用程序。

通过这个应用程序可以与我们在PC上运行的JAVA程序进行通信。

http://www.anotherm.net/档案/2010/10/15/android-usb-connection-to-pc/

Communication between Android Device and PC is possible in one more way.

Through ADB connection via USB.

  1. Port Forwarding.
  2. Server Socket JAVA Program.
  3. Client Socket Android App.

Through this app can communicate with the our JAVA Program running on PC.

http://www.anothem.net/archives/2010/10/15/android-usb-connection-to-pc/

甜宝宝 2024-10-02 12:51:31

编辑:请注意,此答案早于 Android USB 主机和附件 API 的可用性以及在编写后发布的许多设备中发现的支持。

如果你在手机上打开usb调试并且在pc上有从sdk的(开源)adb工具派生的东西,他们就可以通信。电脑必须发起通信,但在会话中,它可以主要是双向的,甚至主要是从设备到电脑。有关 adb shell 和端口转发的信息,请参阅developer.android.com。不需要根。

人们使用蓝牙与 arduino 嵌入式控制器进行通信。

通过 root,我让我的手机充当 USB 主机,但这很痛苦,因为 USB 被占用,我必须使用 wifi 来获取调试 shell。

有些电话在 exusb 连接器或音频线上有一个低压串行端口,但需要 root 和电平转换器才能使用它。

我一直在考虑的另一个想法是在耳机插孔上做一个软件调制解调器,显然日本的某人已经为 android 和 iphone 做了这个想法。这应该不需要 root。

Edit: Please note this answer predates the availability of the Android USB host and accessory APIs and support found in many devices released after it was written.

If you turn on usb debugging on the phone and have something derived from the sdk's (open source) adb tool on the pc, they can communicate. The pc will have to initiate communications but within the sessions it can be mostly bidirectional or even mostly from device to pc. See developer.android.com about the adb shell and port forwarding. Root not required.

People are using bluetooth to talk to arduino embedded controllers.

With root I have made my phone act as a usb host, but it was a pain as I had to use wifi to get a debug shell since the usb was occupied.

Some phones have a low voltage serial port on an extusb connector or audio lines, but root and a level shifter would be required to use this.

Another idea I had been thinking of, doing a software modem on the headset jack, apparently has been done for both android and iphone by someone in Japan. This should not require root.

木格 2024-10-02 12:51:31

对于通过 USB/wlan 进行通信,请查看此项目:http://code.google.com /p/android-notifier/

For communication via usb/wlan take a look at this project: http://code.google.com/p/android-notifier/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文