Skip to content

Commit

Permalink
Merge pull request android#68 from ryondev/master
Browse files Browse the repository at this point in the history
Add camera-open-status check
  • Loading branch information
owahltinez authored Sep 27, 2019
2 parents 0c8f6d2 + f11eb30 commit f40ebef
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ public void onOrientationChanged(int orientation) {
public void onResume() {
super.onResume();
startBackgroundThread();
openCamera();
if (!openCamera()) {
Log.e(TAG, "Camera open fail");
return;
}

// When the screen is turned off and turned back on, the SurfaceTexture is already
// available, and "onSurfaceTextureAvailable" will not be called. In that case, we should
Expand Down Expand Up @@ -765,13 +768,13 @@ private boolean setUpCameraOutputs() {
* Opens the camera specified by {@link #mCameraId}.
*/
@SuppressWarnings("MissingPermission")
private void openCamera() {
private boolean openCamera() {
if (!setUpCameraOutputs()) {
return;
return false;
}
if (!hasAllPermissionsGranted()) {
requestCameraPermissions();
return;
return false;
}

Activity activity = getActivity();
Expand All @@ -792,11 +795,13 @@ private void openCamera() {
// Attempt to open the camera. mStateCallback will be called on the background handler's
// thread when this succeeds or fails.
manager.openCamera(cameraId, mStateCallback, backgroundHandler);
return true;
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
}
return false;
}

/**
Expand Down

0 comments on commit f40ebef

Please sign in to comment.