Browse Source

修复部分机型Activity不可见时,Camera预览失败bug

main
jiangdongguo 7 years ago
parent
commit
9f37b1a964
  1. 1
      app/src/main/AndroidManifest.xml
  2. 22
      app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java
  3. 7
      libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java

1
app/src/main/AndroidManifest.xml

@ -7,6 +7,7 @@
<!--全局异常检测,需添加--> <!--全局异常检测,需添加-->
<!--android:name=".application.MyApplication"--> <!--android:name=".application.MyApplication"-->
<application <application
android:name=".application.MyApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"

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

@ -62,6 +62,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
private CameraViewInterface mUVCCameraView; private CameraViewInterface mUVCCameraView;
private boolean isRequest; private boolean isRequest;
private boolean isPreview;
/** /**
* USB设备事件监听器 * USB设备事件监听器
@ -99,6 +100,9 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
public void onConnectDev(UsbDevice device,boolean isConnected) { public void onConnectDev(UsbDevice device,boolean isConnected) {
if(! isConnected) { if(! isConnected) {
showShortMsg("连接失败,请检查分辨率参数是否正确"); showShortMsg("连接失败,请检查分辨率参数是否正确");
isPreview = false;
}else{
isPreview = true;
} }
} }
@ -125,10 +129,20 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
if(mUSBManager == null)
return;
// 注册USB事件广播监听器 // 注册USB事件广播监听器
if(mUSBManager != null){ mUSBManager.registerUSB();
mUSBManager.registerUSB(); if(!isPreview && mUSBManager.isCameraOpened()) {
mUSBManager.startPreview(mUVCCameraView, new AbstractUVCCameraHandler.OnPreViewResultListener() {
@Override
public void onPreviewResult(boolean result) {
}
});
isPreview = true;
} }
} }
@Override @Override
@ -138,6 +152,10 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
if(mUSBManager != null){ if(mUSBManager != null){
mUSBManager.unregisterUSB(); mUSBManager.unregisterUSB();
} }
if(isPreview && mUSBManager.isCameraOpened()) {
mUSBManager.stopPreview();
isPreview = false;
}
} }
@OnClick({ R.id.btn_contrast,R.id.btn_brightness,R.id.btn_capture_pic, R.id.btn_rec_video,R.id.btn_update_resolution,R.id.btn_restart_camera}) @OnClick({ R.id.btn_contrast,R.id.btn_brightness,R.id.btn_capture_pic, R.id.btn_rec_video,R.id.btn_update_resolution,R.id.btn_restart_camera})

7
libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java

@ -338,6 +338,13 @@ public class USBCameraManager{
} }
} }
// 停止预览
public void stopPreview() {
if(mCameraHandler != null){
mCameraHandler.stopPreview();
}
}
// Camera对焦 // Camera对焦
public void startCameraFoucs(){ public void startCameraFoucs(){
if(mCameraHandler != null){ if(mCameraHandler != null){

Loading…
Cancel
Save