I need to establish bi-directional communication (read/write) between two Android devices exclusively over USB. Wi-Fi and Bluetooth are not options for my use case.
I built an Android app for Device 1 using USB Host Mode. It detects and "discovers" Device 2 when plugged in. It can request permission and open a USB connection to Device 2 using UsbManager
and UsbDeviceConnection
. However, it can't send data yet, because the other device should accept to receive this data. Thus, I assume that my Device 2 should also have an android app to receive this data.
And this is where I'm stuck. I don't understand what Device 2's app should do to enable two-way communication. It's not a host, but it also seems to me that it isn't an accessory.
My Questions:
- What mode should Device 2 (the one being plugged in) operate in? Should it be in USB Accessory Mode, USB Host Mode or something else?
- How can Device 2 send data back to Device 1? I know how to send data from Host to Accessory, but I don't know how the reverse works.
- Are there any examples or documentation on Android-to-Android USB communication? Most guides seem to focus on USB peripherals (e.g., Arduino, keyboards).
I appreciate any guidance, explanations, example implementations or even just small help! Thank you.