Skip to content Skip to sidebar Skip to footer

How To Check Usb Host Support On Android Device Programmatically?

I know that it was supported starting Android 3.1, i mean 'how to check hardware support'

Solution 1:

See: http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_USB_HOST

   context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_USB_HOST);

Solution 2:

I had the same question and after some googling I found this: http://android.serverbox.ch/?p=549

In summary, your app needs to use the UsbManager system service and enumerate through attached USB devices.

mUsbManager = (UsbManager) mApplicationContext.getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> devlist = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviter = devlist.values().iterator();
while (deviter.hasNext()) {
    UsbDevice d = deviter.next();
    if (mUsbManager.hasPermission(d)) {
        UsbInterface usbIf = mDevice.getInterface(1);
        for (int i = 0; i < usbIf.getEndpointCount(); i++) {
            if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                //...
            }
        }
    }
}

Post a Comment for "How To Check Usb Host Support On Android Device Programmatically?"