Trapped camera already in use by another app error

pull/324/head
okafor ezewuzie 7 years ago
parent 14581075b7
commit d4bce6c35b
  1. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  2. 19
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraLaunchException.java

@ -177,6 +177,14 @@ abstract class CameraController implements
if (mState >= STATE_STARTING) return; if (mState >= STATE_STARTING) return;
mState = STATE_STARTING; mState = STATE_STARTING;
LOG.i("Start:", "about to call onStart()", ss()); LOG.i("Start:", "about to call onStart()", ss());
// Added this because an exception is raised on the onStart method below
// when another app is current accessing the camera
try {
onStart();
}catch (RuntimeException e){
throw new CameraLaunchException(e);
}
onStart(); onStart();
LOG.i("Start:", "returned from onStart().", "Dispatching.", ss()); LOG.i("Start:", "returned from onStart().", "Dispatching.", ss());
mState = STATE_STARTED; mState = STATE_STARTED;

@ -0,0 +1,19 @@
package com.otaliastudios.cameraview;
/**
* This exception is thrown when a third party application is currently using the camera of the device and thus the current app cannot launch the camera view
* <p></p>
* This exception is made to extend {@link CameraException} signifying that it is an expected exception and should not crash the app.
*<p></p>
* The implementation of the {@link CameraListener} supplied should check if the {@link CameraException} in the implementation of the
* {@link CameraListener#onCameraError(CameraException)} method is an instance of {@link CameraLaunchException}. If it is an instance of
* {@link CameraLaunchException}, an appropriate message should be displayed to the user indicating that a third party app is currently
* using the camera and that needs to be turned off before the camera can be launched from the current app
*
*/
public class CameraLaunchException extends CameraException {
public CameraLaunchException(Throwable cause) {
super(cause);
}
}
Loading…
Cancel
Save