usb驅(qū)動(dòng)來源https://github.com/jiangdongguo/AndroidUSBCamera
android8以下沒有問題彼乌;華為8x升級(jí)到android9之后發(fā)現(xiàn)不能連接攝像頭,發(fā)現(xiàn)主要是協(xié)議過濾和獲取到的不匹配:
華為8x為例:
android8 返回的是class =239 subClass = 2
android9 返回的是class =14 subClass = 9
適配:
1洋访、修改
image.png
<usb>
<usb-device class="239" subclass="2" /> <!-- all device of UVC -->
<usb-device class="14" subclass="9" /> <!-- 華為8x of UVC -->
<usb-device class="2" subclass="0" />
</usb>
2贤斜、修改UVCCameraHelper.java
public List<UsbDevice> getUsbDeviceList() {
List<DeviceFilter> deviceFilters = DeviceFilter
.getDeviceFilters(context, R.xml.device_filter);
if (mUSBMonitor == null || deviceFilters == null)
return null;
//獲取多個(gè)設(shè)備過濾條件;之前只返回了第一個(gè)
return mUSBMonitor.getDeviceList(deviceFilters);
}
3裕寨、修改USBMonitor.java
public List<UsbDevice> getDeviceList(final List<DeviceFilter> filters) throws IllegalStateException {
if (destroyed) throw new IllegalStateException("already destroyed");
final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
final List<UsbDevice> result = new ArrayList<UsbDevice>();
if (deviceList != null) {
if ((filters == null) || filters.isEmpty()) {
result.addAll(deviceList.values());
} else {
for (final UsbDevice device : deviceList.values()) {
for (final DeviceFilter filter : filters) {
//增加判斷filter.mSubclass == device.getDeviceSubclass()
if (((filter != null) && filter.matches(device)) || (filter != null && filter.mSubclass == device.getDeviceSubclass())) {
// when filter matches
if (!filter.isExclude) {
result.add(device);
}
break;
}
}
}
}
}
return result;
}
4楼熄、如果還發(fā)現(xiàn)有其他的class 和 subClass 直接添加在配置文件中既可
若有誤請(qǐng)聯(lián)系反饋………………