0

I'm trying to gain a deeper understanding of the Android USB APIs. I have played with the USB Host APIs and have successfully connected various devices (USB stick, USB hub with other devices attached) to my Android phone (Phone as host). I discovered the devices, pulled information, explored the interfaces, endpoint information etc.

When I plug my Phone into my PC I assumed the PC would be enumerated as either a Device or an Accessory, but it does not show up as either.

Here is the code I'm using to discover all Devices and Accessories

   UsbManager manager = (UsbManager) getSystemService(USB_SERVICE);

   UsbAccessory[] as = manager.getAccessoryList();
   if (as != null) {
       Log.i("Usb", "Found Accessory " + as[0].toString());
   } else {
       Log.i("Usb", "no accessory found");
   }

   HashMap<String, UsbDevice> ds = manager.getDeviceList();
   if (ds == null || ds.isEmpty()) {
       Log.i("Usb", "no devices found");
   } else {
       for (Map.Entry e : ds.entrySet()) {
           Log.i("Usb", "Found device " + e.getValue().toString());
       }
   }

Why does the phone not see the PC as either a Device or an Accessory?

Yirmi
  • 332
  • 2
  • 13

1 Answers1

0

When I plug my Phone into my PC I assumed the PC would be enumerated as either a Device or an Accessory, but it does not show up as either.

Nope. The PC is always the host, the Android enumerates on the PC as a device.

Thus you will never get the PC in UsbManager device list. This API is only used when Android is the host.

Turbo J
  • 7,563
  • 1
  • 23
  • 43