How to check usb host support on android device programmatically?

妖精的绣舞 提交于 2019-12-10 18:32:27

问题


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


回答1:


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

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



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


来源:https://stackoverflow.com/questions/15598957/how-to-check-usb-host-support-on-android-device-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!