Nankai

How to leverage the accessory mode to communicate between 2 Android devices. You connect 2 devices via one USB-cable + one USB-OTG adapter and chat between devices ( or exchange any other data in a real-world application ).

The App comes in 2 flavors — one host flavor and one device flavor. You need to install one of these flavors on each device.

Install

for the host:

for the device:

Notes

Be aware that the direction of the cable matters even though there is micro-USB on both ends. The OTG adapter has to be on the device with the host flavor installed.

A core problem was to figure out how to get a device to switch to accessory mode — the Idea was taken from some C code inside the Android Compatibility Test Suite — this is how it looks in java here:

Source: https://github.com/VNAPNIC/USB-accessory-sample