Skip to main content

buildfire.services.camera.barcodeScanner

This service accesses the device camera and scans for barcodes or qr codes in their various forms.

Info

This service works only on devices

Requirements

Widget

Include barcodeScanner.js file in widget header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../scripts/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/services/camera/barcodeScanner.js"></script>
</head>

plugin.json

In plugin.json add BarCodeScanner in your features array "features" : [{"name" : "BarCodeScanner"}]

Methods

scan()

buildfire.services.camera.barcodeScanner.scan(options, callback)

This will invoke the scanning process. It may also ask the user for permission to access the Camera if it hasn't previously.

buildfire.services.camera.barcodeScanner.scan(
{
preferFrontCamera: true,
showFlipCameraButton: true,
formats: "QR_CODE,PDF_417",
},
(err, result) => {
if (err) return console.error(err);

buildfire.dialog.alert({
message: `Barcode scanned! Result: ${result.text} Format: ${result.format} Cancelled: ${result.cancelled}`,
});
}
);

options

NameTypeRequiredDescriptionDefault
preferFrontCamerabooleannoPreference to start with the Front Camera or Back if available on the device.false
showFlipCameraButtonbooleannoAllow user to flip between camera'sfalse
showTorchButtonbooleannoTurns on the flashlightfalse
torchOnbooleannoAndroid only. Launch with the torch switched on (if available)false
promptstringnoPrompt to display to user"Place a barcode inside the scan area"
resultDisplayDurationnumbernoAndroid only. Display scanned text for certain number of milliseconds. 0 suppresses it entirely1500
formatsstringnoComma separated values. See table below for possible formatsAll except "PDF_417" and "RSS_EXPANDED"

callback(err, result)

Callback function after scanning the code

NameTypeDescription
errstringerror string, null when operation is successful
resultobjectScanned barcode / qrcode result

result

NameTypeDescription
textstringScanned result text
formatstringScanned barcode / qrcode format
cancelledbooleanIndicates if scan was cancelled

Supported Barcode Formats

The following barcode types are currently supported:

AndroidiOS
"QR_CODE""QR_CODE"
"DATA_MATRIX""DATA_MATRIX"
"UPC_E""UPC_E"
"UPC_A""UPC_A"
"EAN_8""EAN_8"
"EAN_13""EAN_13"
"CODE_128""CODE_128"
"CODE_39""CODE_39"
"CODE_93"
"CODABAR"
"ITF""ITF"
"RSS14"
"RSS_EXPANDED"