cross-platform barcode scanner for cordova
- Android
- iOS
- Windows 8
- Windows Phone 8
cordova plugin add cordova-plugin-barcodescanner
Or if you want to use the development version (nightly build), which maybe not stable!:
cordova plugin add cordova-plugin-barcodescanner@next
execute the runIntegrationTests.sh
script for a specific platform:
PLATFORM='android' ./runIntegrationTests.sh
PLATFORM='ios' ./runIntegrationTests.sh
The Android source for this project includes an Android Library Project. plugman currently doesn't support Library Project refs, so its been prebuilt as a jar library. Any updates to the Library Project should be committed with an updated jar.
The plugin creates the object cordova/plugin/BarcodeScanner
with the method scan(success, fail)
.
The following barcode types are currently supported:
- QR_CODE
- DATA_MATRIX
- UPC_E
- UPC_A
- EAN_8
- EAN_13
- CODE_128
- CODE_39
- CODE_93
- CODABAR
- ITF
- RSS14
- PDF417
- RSS_EXPANDED
- QR_CODE
- DATA_MATRIX
- UPC_E
- UPC_A
- EAN_8
- EAN_13
- CODE_128
- CODE_39
- ITF
- UPC_A
- UPC_E
- EAN_8
- EAN_13
- CODE_39
- CODE_93
- CODE_128
- ITF
- CODABAR
- MSI
- RSS14
- QR_CODE
- DATA_MATRIX
- AZTEC
- PDF417
- UPC_A
- UPC_E
- EAN_8
- EAN_13
- CODE_39
- CODE_93
- CODE_128
- ITF
- CODABAR
- MSI
- RSS14
- QR_CODE
- DATA_MATRIX
- AZTEC
- PDF417
success
and fail
are callback functions. Success is passed an object with data, type and cancelled properties. Data is the text representation of the barcode data, type is the type of barcode detected and cancelled is whether or not the user cancelled the scan.
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);
}
);
The plugin creates the object window.plugins.barcodeScanner
with the method encode(type, data, success, fail)
.
Supported encoding types:
- TEXT_TYPE
- EMAIL_TYPE
- PHONE_TYPE
- SMS_TYPE