From 4ef4dfb51fb9a5c73c5a54d58a61ad577b89397f Mon Sep 17 00:00:00 2001 From: Woon Tien Jing Date: Sat, 6 Dec 2014 16:38:00 +0800 Subject: [PATCH] Added front/back camera option --- README.md | 1 + android/ZBarScannerActivity.java | 26 ++++++++++++++++++++++++-- ios/CsZBar.m | 9 +++++++++ www/zBar.js | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da6d7bc..0035824 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Arguments: { text_title: "OPTIONAL Title Text - default = 'Scan QR Code'", // Android only text_instructions: "OPTIONAL Instruction Text - default = 'Please point your camera at the QR code.'", // Android only + camera: "front" || "back" // defaults to "back" } ``` diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index be6a2c3..55227ae 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -1,6 +1,7 @@ package org.cloudsky.cordovaPlugins; import java.io.IOException; +import java.lang.RuntimeException; import org.json.JSONException; import org.json.JSONObject; @@ -8,6 +9,7 @@ import android.app.Activity; import android.content.Intent; import android.content.res.Resources; import android.hardware.Camera; +import android.hardware.Camera.CameraInfo; import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.AutoFocusCallback; import android.os.Bundle; @@ -47,6 +49,9 @@ implements SurfaceHolder.Callback { private ImageScanner scanner; private int surfW, surfH; + // Customisable stuff + String whichCamera; + // For retrieving R.* resources, from the actual app package // (we can't use actual.application.package.R.* in our code as we // don't know the applciation package name when writing this plugin). @@ -75,6 +80,7 @@ implements SurfaceHolder.Callback { catch (JSONException e) { params = new JSONObject(); } String textTitle = params.optString("text_title"); String textInstructions = params.optString("text_instructions"); + whichCamera = params.optString("camera"); // Initiate instance variables autoFocusHandler = new Handler(); @@ -119,10 +125,26 @@ implements SurfaceHolder.Callback { super.onResume(); try { - camera = Camera.open(); - } catch (Exception e){ + if(whichCamera.equals("front")) { + int numCams = Camera.getNumberOfCameras(); + CameraInfo cameraInfo = new CameraInfo(); + for(int i=0; i