6

I am trying to learn Android USB Host/Accessory connection. I read android devices can act usb host or usb accessory. Therefore I create two project one of them usb host project, other usb accessory project. I installed these projects to two different android devices. One of them has usb host(Device A) project, other has usb accessory(Device B) project.

My question is, I can connect with usb host project to Device B. I can see all information about device. But In accessory project( Device B) i can not see any thing about device A.

manager.getAccessoryList() always return null. My usb accessory project code is here.

UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

for (UsbAccessory accessory : manager.getAccessoryList()) {
    String list = " DESCRIPTION : " + accessory.getDescription() + " MODEL : " + accessory.getModel() + " MANUFACTURER : " + accessory.getManufacturer() + " SERIAL : " + accessory.getSerial();
    Toast.makeText(this, list, Toast.LENGTH_LONG).show();
}
B770
  • 1,272
  • 3
  • 17
  • 34
Zapateus
  • 516
  • 3
  • 8
  • 21

2 Answers2

1

Try this https://github.com/quandoo/android2android-accessory

Even I was getting accessory list as 0. But in the github project, they have first sent some control message from one android device acting as a host to other device which is accessory. After sending the control message, I get the accessory list non-zero.

user1527969
  • 66
  • 1
  • 6
  • 1
    Not sure the same or even so up to date but found similar project here: https://github.com/manishsharma004/android2android-accessory – epic Oct 13 '21 at 12:55
0

That's because when you connect an accessory to Device B, your accessory which is acting as US B host must implement the Android Open Accessory Protocol (AOAP). See Connecting over USB. Since Device A (host), does not implement the AOAP, Device B will refuse to communicate with Device A beyond a handshake attemp.

Luis
  • 3,451
  • 1
  • 27
  • 41
  • 1
    Do u mean that its possible to communicate between two android devices over AOAP? My understanding was AOAP communication is possible between an android device supporting AOAP and a USB accessory like arduino which supports AOAP. Can you please clarify? – Kozlov Apr 24 '14 at 05:58
  • 1
    @Kozlov I meant that an Android device running in USB Accessory mode will only communicate with a USB host that implements the AOAP. – Luis Apr 24 '14 at 15:54