最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to establish communication between two Android devices over USB? - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论