简体   繁体   中英

How to check usb host support on android device programmatically?

我知道它支持启动Android 3.1,我的意思是“如何检查硬件支持”

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM