← Plugins / 1D Barcode Scanner
An open-source Cordova plugin that scans 1D linear barcodes on iOS and Android
using each platform's native, offline decoder — no cloud service and no account required.
Android uses CameraX with bundled Google ML Kit; iOS uses AVFoundation's built-in
AVCaptureMetadataOutput.
The full list is also available at runtime on cordova.plugins.barcodeScanner.FORMATS.
| Component | Version |
|---|---|
| Cordova CLI | >= 9 |
| cordova-android | >= 12 (Android API 33+ / AndroidX) |
| cordova-ios | >= 6 |
| Devices | iOS 11+ · Android 5.0+ (API 21) with a camera |
Add the plugin from the npm registry:
cordova plugin add cordova-plugin-1d-barcode-scanner
On iOS you can override the camera usage description shown to the user at install time:
cordova plugin add cordova-plugin-1d-barcode-scanner \
--variable CAMERA_USAGE_DESCRIPTION="We use the camera to scan product barcodes."
On Android the CAMERA permission and the runtime request are handled automatically — you don't need to add anything.
The plugin is exposed as cordova.plugins.barcodeScanner.
scan(success, error, options)| Argument | Type | Description |
|---|---|---|
success | Function | Called with a result object (see below). Required. |
error | Function | Called with an error message string. Optional. |
options | Object | Optional configuration (see below). |
Options
| Key | Type | Default | Description |
|---|---|---|---|
prompt | String | "Point your camera at a barcode" | Text shown on the scanner overlay. |
formats | String[] | all supported formats | Restrict the accepted symbologies, e.g. ['EAN_13', 'CODE_128']. Any 2D format is ignored. |
beep | Boolean | true | Play a short beep on a successful scan. |
Result object passed to success:
{
"text": "4006381333931",
"format": "EAN_13",
"cancelled": false
}
When the user dismisses the scanner, success is still called with
{ "text": "", "format": "", "cancelled": true }.
Scan a barcode after deviceready and handle the result:
document.addEventListener("deviceready", onReady, false);
function onReady() {
cordova.plugins.barcodeScanner.scan(
function (result) {
if (result.cancelled) {
console.log("User cancelled the scan");
return;
}
console.log("Barcode: " + result.text + " (" + result.format + ")");
},
function (error) {
console.error("Scan failed: " + error);
},
{
prompt: "Scan the product barcode",
formats: ["EAN_13", "EAN_8", "UPC_A", "CODE_128"],
beep: true
}
);
}
BarcodeScannerOptions.setBarcodeFormats(...) listing only 1D formats. 2D formats such as FORMAT_QR_CODE are never enabled, so they are never decoded.AVCaptureMetadataOutput.metadataObjectTypes is set to only 1D AVMetadataObjectType values, and a defensive check additionally drops any QR result.compileSdk — make sure you're on cordova-android >= 12 (CameraX / ML Kit require compileSdk 33+).NSCameraUsageDescription is present in your *-Info.plist (added automatically on install).