diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java index 3fb41e8a..b9eec915 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java @@ -177,6 +177,14 @@ abstract class CameraController implements if (mState >= STATE_STARTING) return; mState = STATE_STARTING; 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(); LOG.i("Start:", "returned from onStart().", "Dispatching.", ss()); mState = STATE_STARTED; diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraLaunchException.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraLaunchException.java new file mode 100644 index 00000000..e8521d82 --- /dev/null +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraLaunchException.java @@ -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 + *

+ * This exception is made to extend {@link CameraException} signifying that it is an expected exception and should not crash the app. + *

+ * 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); + } +}