DedrisFrameworkDedrisFramework

← Plugins  /  1D Barcode Scanner

🔦

1D Barcode Scanner

cordova-plugin-1d-barcode-scanner
iOS Android 📦 npm ⚖️ MIT

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.

⚠️ Linear barcodes only. This plugin scans EAN, UPC, Code 128, Code 39, Code 93, ITF and Codabar. QR codes and other 2D codes (Aztec, Data Matrix, PDF417) are intentionally not scanned — any 2D format you pass is simply ignored.

Supported formats

EAN_13EAN_8 UPC_AUPC_E CODE_39CODE_93 CODE_128ITF CODABAR

The full list is also available at runtime on cordova.plugins.barcodeScanner.FORMATS.

Requirements

ComponentVersion
Cordova CLI>= 9
cordova-android>= 12 (Android API 33+ / AndroidX)
cordova-ios>= 6
DevicesiOS 11+ · Android 5.0+ (API 21) with a camera

Installation

Add the plugin from the npm registry:

terminal
cordova plugin add cordova-plugin-1d-barcode-scanner

On iOS you can override the camera usage description shown to the user at install time:

terminal
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.

API

The plugin is exposed as cordova.plugins.barcodeScanner.

scan(success, error, options)

ArgumentTypeDescription
successFunctionCalled with a result object (see below). Required.
errorFunctionCalled with an error message string. Optional.
optionsObjectOptional configuration (see below).

Options

KeyTypeDefaultDescription
promptString"Point your camera at a barcode"Text shown on the scanner overlay.
formatsString[]all supported formatsRestrict the accepted symbologies, e.g. ['EAN_13', 'CODE_128']. Any 2D format is ignored.
beepBooleantruePlay a short beep on a successful scan.

Result object passed to success:

result
{
  "text": "4006381333931",
  "format": "EAN_13",
  "cancelled": false
}

When the user dismisses the scanner, success is still called with { "text": "", "format": "", "cancelled": true }.

Usage example

Scan a barcode after deviceready and handle the result:

www/js/app.js
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
    }
  );
}

How "no QR" is enforced

Troubleshooting

📦 Package: this page documents cordova-plugin-1d-barcode-scanner on npm. Source code, issues and the full sample app are on GitHub. Released under the MIT License © dedrisproject.
← Back to plugins Start a project