Browse Source

fix a bug on Android 9.0

main
Jiangdg 6 years ago
parent
commit
af3fc00986
  1. 6
      app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java
  2. 1
      libusbcamera/src/main/java/com/jiangdg/usbcamera/UVCCameraHelper.java
  3. 9
      libusbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java

6
app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java

@ -72,10 +72,6 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
@Override @Override
public void onAttachDev(UsbDevice device) { public void onAttachDev(UsbDevice device) {
if (mCameraHelper == null || mCameraHelper.getUsbDeviceCount() == 0) {
showShortMsg("check no usb camera");
return;
}
// request open permission // request open permission
if (!isRequest) { if (!isRequest) {
isRequest = true; isRequest = true;
@ -141,7 +137,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
mUVCCameraView = (CameraViewInterface) mTextureView; mUVCCameraView = (CameraViewInterface) mTextureView;
mUVCCameraView.setCallback(this); mUVCCameraView.setCallback(this);
mCameraHelper = UVCCameraHelper.getInstance(); mCameraHelper = UVCCameraHelper.getInstance();
mCameraHelper.setDefaultFrameFormat(UVCCameraHelper.FRAME_FORMAT_YUYV); mCameraHelper.setDefaultFrameFormat(UVCCameraHelper.FRAME_FORMAT_MJPEG);
mCameraHelper.initUSBMonitor(this, mUVCCameraView, listener); mCameraHelper.initUSBMonitor(this, mUVCCameraView, listener);

1
libusbcamera/src/main/java/com/jiangdg/usbcamera/UVCCameraHelper.java

@ -238,6 +238,7 @@ public class UVCCameraHelper {
List<DeviceFilter> deviceFilters = DeviceFilter List<DeviceFilter> deviceFilters = DeviceFilter
.getDeviceFilters(mActivity.getApplicationContext(), R.xml.device_filter); .getDeviceFilters(mActivity.getApplicationContext(), R.xml.device_filter);
if (mUSBMonitor == null || deviceFilters == null) if (mUSBMonitor == null || deviceFilters == null)
// throw new NullPointerException("mUSBMonitor ="+mUSBMonitor+"deviceFilters=;"+deviceFilters);
return null; return null;
// matching all of filter devices // matching all of filter devices
return mUSBMonitor.getDeviceList(deviceFilters); return mUSBMonitor.getDeviceList(deviceFilters);

9
libusbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java

@ -181,6 +181,7 @@ public final class USBMonitor {
mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0); mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0);
final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
// ACTION_USB_DEVICE_ATTACHED never comes on some devices so it should not be added here // ACTION_USB_DEVICE_ATTACHED never comes on some devices so it should not be added here
filter.addAction(ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
context.registerReceiver(mUsbReceiver, filter); context.registerReceiver(mUsbReceiver, filter);
} }
@ -311,7 +312,15 @@ public final class USBMonitor {
final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList(); final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
// store those devices info before matching filter xml file // store those devices info before matching filter xml file
String fileName = Environment.getExternalStorageDirectory()+ "/USBCamera/failed_devices.txt"; String fileName = Environment.getExternalStorageDirectory()+ "/USBCamera/failed_devices.txt";
File logFile = new File(fileName); File logFile = new File(fileName);
if(! logFile.exists()) {
try {
logFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileWriter fw = null; FileWriter fw = null;
PrintWriter pw = null; PrintWriter pw = null;
final List<UsbDevice> result = new ArrayList<UsbDevice>(); final List<UsbDevice> result = new ArrayList<UsbDevice>();

Loading…
Cancel
Save