0

I want to get list of all connected hosts to my android usb device.

UsbManager manager = (UsbManager)parent.getSystemService(Context.USB_SERVICE);
UsbAccessory[] accessoryList = manager.getAccessoryList();
if(accessoryList == null){
Log.w(TAG, "AccessoryList is null");
}

This is returning null to LogCat.

Also in BroadcastReceiver,

UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);

is also returning null.

My PC is connected to android and on running the application, the app is asking for Permission to connect to USB host.

What is wrong? Please help me out.

1 Answer 1

1

From the documentation of UsbManager:

This class allows you to access the state of USB and communicate with USB devices. Currently only host mode is supported in the public API.

When you connect your Android device to the PC, the PC is a USB Host while the Android is a USB device. Thus you cannot use the current UsbManager API - it would only apply if you were connected USB peripherals to a phone with both hardware and software support for that.

Android doesn't really have a desktop<->mobile "sync" API in the tradition of earlier USB connected phones - there are some possibilities, but the primary assumption is that end users will make use of cloud based services from Google or others for this purpose.

1
  • 1
    That's kind of moot since there can only be one host in a USB bus - in this case the PC. Commented Nov 12, 2013 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.