diff --git a/README.md b/README.md index 0035824..fb17160 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,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" + flash: "on" || "off" || "auto" // defaults to "auto" } ``` diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index 4ada5a4..c84629f 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -14,6 +14,7 @@ import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.AutoFocusCallback; import android.os.Bundle; import android.os.Handler; +import android.util.Log; import android.view.Gravity; import android.view.SurfaceHolder; import android.view.SurfaceView; @@ -51,6 +52,7 @@ implements SurfaceHolder.Callback { // Customisable stuff String whichCamera; + String flashMode; // For retrieving R.* resources, from the actual app package // (we can't use actual.application.package.R.* in our code as we @@ -81,6 +83,7 @@ implements SurfaceHolder.Callback { String textTitle = params.optString("text_title"); String textInstructions = params.optString("text_instructions"); whichCamera = params.optString("camera"); + flashMode = params.optString("flash"); // Initiate instance variables autoFocusHandler = new Handler(); @@ -147,6 +150,19 @@ implements SurfaceHolder.Callback { return; } + Camera.Parameters camParams = camera.getParameters(); + if(flashMode.equals("on")) { + camParams.setFlashMode(Camera.Parameters.FLASH_MODE_ON); + } else if(flashMode.equals("off")) { + camParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); + } else { + camParams.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); + } + try { camera.setParameters(camParams); } + catch (RuntimeException e) { + Log.d("csZBar", "Unsupported camera parameter reported for flash mode: "+flashMode); + } + tryStartPreview(); } diff --git a/ios/CsZBar.m b/ios/CsZBar.m index c189bbe..0af3803 100644 --- a/ios/CsZBar.m +++ b/ios/CsZBar.m @@ -47,12 +47,18 @@ // Get user parameters NSDictionary *params = (NSDictionary*) [command argumentAtIndex:0]; - NSString * camera = [params objectForKey:@"camera"]; + NSString *camera = [params objectForKey:@"camera"]; if([camera isEqualToString:@"front"]) { // We do not set any specific device for the default "back" setting, // as not all devices will have a rear-facing camera. self.scanReader.cameraDevice = UIImagePickerControllerCameraDeviceFront; } + NSString *flash = [params objectForKey:@"flash"]; + if([flash isEqualToString:@"on"]) { + self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; + } else if([flash isEqualToString:@"off"]) { + self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; + } // Hack to hide the bottom bar's Info button... http://stackoverflow.com/a/16353530 UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3]; diff --git a/www/zBar.js b/www/zBar.js index 1aa4bc0..edadc91 100644 --- a/www/zBar.js +++ b/www/zBar.js @@ -13,6 +13,7 @@ ZBar.prototype = { if(params.text_title === undefined) params.text_title = "Scan QR Code"; if(params.text_instructions === undefined) params.text_instructions = "Please point your camera at the QR code."; if(params.camera != "front") params.camera = "back"; + if(params.flash != "on" && params.flash != "off") params.flash = "auto"; exec(success, failure, 'CsZBar', 'scan', [params]); },