Android device acting as an accessory

I have 2 Android devices, which I would like to connect with a USB OTG cable and have back-and-forth communication between the two devices. From what I understand, one Android device will act as the USB Host (Nexus 7 running 4.4) and the other Android device will act as a USB Accessory (Galaxy Nexus running 4.2.2). I've tried googling around for an answer, but I can only seem to find articles explaining how to connect an Android device to a USB accessory (like a USB mouse or keyboard), not how to treat an Android device as the USB accessory itself. So, following this page, I have configured an app on the Nexus 7 to be the USB Host. I can find the connected Galaxy Nexus based on its product id & vendor id, form a connection to the Android Open Accessory Protocol and successfully connect over USB. From what I can tell, the Nexus 7 can successfully send bytes to the Galaxy Nexus. My question is how to access this connection on the Galaxy Nexus side. I have added permissions and the USB filter into the manifest, so the desired app opens on the Galaxy Nexus once the USB connection is established, but I can't figure out how to receive the data coming in from the Nexus 7 or how to send data from the Galaxy Nexus back to the Nexus 7. Any help would be greatly appreciated! Thanks!

asked Nov 26, 2013 at 19:31 lifeson106 lifeson106 513 4 4 silver badges 11 11 bronze badges

Whoever called this off topic is severely mistaken. This concerns software development utilizing the android APIs.

Commented Nov 26, 2013 at 19:42

There is no generic "USB device" API in Android for operating as a USB slave. Your best best is probably to look at the ADK protocol - have the "host" device play the role of the external embedded USB host (ie, the job normally done by the ADK board, Arduino + USB host shield, or ioio board). Then you can use the ADK APIs on the "slave" device.