4ntoine
4ntoine

Reputation: 20422

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"

Upvotes: 4

Views: 3286

Answers (2)

GabrielWeis
GabrielWeis

Reputation: 340

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

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

Upvotes: 2

Peter Tran
Peter Tran

Reputation: 1669

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) {
                //...
            }
        }
    }
}

Upvotes: 0

Related Questions