Reputation: 1335
I have completed all parts of my app, and now I need to use the front camera to scan instead of the back camera, but having issue of opening it.
Here is the script for the camera.
function scanTrivago()
{
cordova.plugins.barcodeScanner.scan(
function (result) {
if(!result.cancelled)
{
trivagoNumber(result.text);
path="/confirm-checkin-1/";
// alert("Barcode type is: " + result.format);
// alert("Decoded text is: " + result.text);
}
else
{
trivagoNumber(result.text);
path="/check-in/";
}
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
I use exactly the function from this site, https://www.sitepoint.com/scanning-qr-code-cordova/ and everything works fine with my simple javascript, but not able to switch the camera to the front.
Upvotes: 0
Views: 164
Reputation: 9272
The plugin docs on github have a better example of usage, including a preferFrontCamera
option:
A full example could be:
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
},
{
preferFrontCamera : true, // iOS and Android
showFlipCameraButton : true, // iOS and Android
showTorchButton : true, // iOS and Android
torchOn: true, // Android, launch with the torch switched on (if available)
saveHistory: true, // Android, save scan history (default false)
prompt : "Place a barcode inside the scan area", // Android
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
disableAnimations : true, // iOS
disableSuccessBeep: false // iOS and Android
}
);
Upvotes: 1