Connect two android devices via USB

3.9k Views Asked by At

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. 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

2

There are 2 best solutions below

0
On

USB is host initiated, so it's not surprising that this is not working. Your device that is functioning as the USB device should respond to requests initiated from the USB host. 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. 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].

3
On

Use OTG Cable to interact with your board and phone. Its easily available in the market.