diff --git a/android/src/com/google/zxing/client/android/camera/CameraManager.java b/android/src/com/google/zxing/client/android/camera/CameraManager.java index 9349b252f..7fc273116 100755 --- a/android/src/com/google/zxing/client/android/camera/CameraManager.java +++ b/android/src/com/google/zxing/client/android/camera/CameraManager.java @@ -52,6 +52,7 @@ public final class CameraManager { private Rect framingRectInPreview; private boolean initialized; private boolean previewing; + private int requestedCameraId = -1; private int requestedFramingRectWidth; private int requestedFramingRectHeight; /** @@ -65,7 +66,7 @@ public final class CameraManager { this.configManager = new CameraConfigurationManager(context); previewCallback = new PreviewCallback(configManager); } - + /** * Opens the camera driver and initializes the hardware parameters. * @@ -75,8 +76,14 @@ public final class CameraManager { public synchronized void openDriver(SurfaceHolder holder) throws IOException { Camera theCamera = camera; if (theCamera == null) { - theCamera = OpenCameraInterface.open(); - if (theCamera == null) { + + if (requestedCameraId > -1) { + theCamera = OpenCameraInterface.open(requestedCameraId); + } else { + theCamera = OpenCameraInterface.open(); + } + + if (theCamera == null) { throw new IOException(); } camera = theCamera; @@ -265,6 +272,21 @@ public final class CameraManager { return framingRectInPreview; } + + /** + * Allows third party apps to specify the camera ID, rather than determine + * it automatically based on available cameras and their orientation. + * + * @param cameraId camera ID of the camera to use + */ + public synchronized void setManualCameraId(int cameraId) { + if (initialized) { + // FIXME throw exception? Just store for future use? Do not want to suddenly swap cameras! + } else { + requestedCameraId = cameraId; + } + } + /** * Allows third party apps to specify the scanning rectangle dimensions, rather than determine * them automatically based on screen resolution.