一、java代码,一般USB视频设备类代码为239,找到一个接口的类代码为 UsbConstants.USB_CLASS_VIDEO (值为 0x0e),则认为该设备是视频设备。
private boolean is_plugin_usb_camera_device()
{
UsbDevice list_usb_device = null;
mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
final HashMap<String, UsbDevice> devMap = mUsbManager.getDeviceList();
final List<UsbDevice> devList = new ArrayList<UsbDevice>();
devList.addAll(devMap.values());
for (int i= 0; i< devList.size(); i++) {
// 遍历设备的接口来检查是否有视频接口
for (int j = 0; j < devList.get(i).getInterfaceCount(); j++) {
UsbInterface usbInterface = devList.get(i).getInterface(j);
if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VIDEO) {
Log.d(TAG, "Found a usb camera device,usb device class is "+ UsbConstants.USB_CLASS_VIDEO);
}
}
if (devList.get(i).getDeviceClass() == 239) { // 一般USB视频设备类代码为239,这里获取第一个图像设备,也可以通过vendorId之类获取指定设备
list_usb_device = devList.get(i);
Log.d(TAG, "Found a usb camera device,"+ " vid:" + list_usb_device.getVendorId() + " pid:" + list_usb_device.getProductId());
//break;
}
}
if (list_usb_device == null) {
return false;
}
return true;
}
二、运行效果

三、执行cat /sys/kernel/debug/usb/devices ,注意Cls=0e(video)

1981

被折叠的 条评论
为什么被折叠?



