简体   繁体   English

通过USB连接两个Android设备

[英]Connect two android devices via USB

I'm trying to figure out how to connect two Android powered devices, namely a smartphone (Android 4.1.2) and an android developer board (Android 4.0.4) with apps running on each, via USB and get them to communicate with each other. 我试图弄清楚如何通过USB连接两个Android驱动的设备,即智能手机(Android 4.1.2)和android开发人员板(Android 4.0.4),并在每个设备上运行的应用程序相互连接。其他。 Right now the developer board is running as the host and the phone as an accessory. 现在,开发板作为主机运行,电话作为附件运行。 The hosts app is searching for connected devices and is able to identify the phone as a device, but the app running on the phone isn't able to find the host. 主机应用正在搜索连接的设备,并且能够将手机识别为设备,但是在手机上运行的应用无法找到主机。 I've searched the web for quite a while now (!!) but I didn't come up with anything helpful yet that solved my problem. 我已经在网上搜索了很长时间(!!),但是我没有提出任何有用的解决方案。 For my project it is crucial that I use an USB connection, so please don't propose that I use bluetooth, WiFi, or anything else... Regards 对于我的项目,使用USB连接至关重要,因此请不要建议我使用蓝牙,WiFi或其他任何方式。

USB is host initiated, so it's not surprising that this is not working. USB是主机启动的,因此不起作用并不奇怪。 Your device that is functioning as the USB device should respond to requests initiated from the USB host. 您充当USB设备的设备应响应从USB主机发起的请求。 You will probably have to create some sort of vendor specific protocol around this. 您可能必须围绕此创建某种特定于供应商的协议。 I don't know what you are trying to do with this connection, but if the device needs to know things on the host you will need to bake this in to your protocol definition and send that information directly to the device. 我不知道您要使用此连接做什么,但是如果设备需要了解主机上的信息,则需要将其添加到协议定义中并将该信息直接发送到设备。

What you could try doing is using both devices as a host and connecting a USB to UART bridge device between them, then you can transmit data generically in any direction by using the serial connection (through USBManager if the USB protocol is available, or some Android Java Serial class if it is not), plus you don't have to worry about the host-device connection. 您可以尝试将两个设备都用作主机并将USB连接到它们之间的UART桥接设备,然后可以使用串行连接(如果有USB协议,可以通过USBManager或某些Android设备)以任何方向通用地传输数据Java串行类(如果不是),那么您不必担心主机设备连接。 This would look something like this: 看起来像这样:

[Android 4.1.2 Device]<--USB Connection-->[USB to UART Bridge]<--Serial Connection-->[USB to UART Bridge]<--USB Connection-->[Android 4.0.4 Device] . [Android 4.1.2 Device]<--USB Connection-->[USB to UART Bridge]<--Serial Connection-->[USB to UART Bridge]<--USB Connection-->[Android 4.0.4 Device]

Use OTG Cable to interact with your board and phone. 使用OTG 电缆与您的电路板和电话进行交互。 Its easily available in the market. 它很容易在市场上买到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM