Barcode Scanner

Improve this doc

The Barcode Scanner Plugin opens a camera view and automatically scans a barcode, returning the data back to you.

Requires Cordova plugin: phonegap-plugin-barcodescanner. For more info, please see the BarcodeScanner plugin docs.

Repo: https://github.com/phonegap/phonegap-plugin-barcodescanner

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add phonegap-plugin-barcodescanner
    $ npm install --save @ionic-native/barcode-scanner
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { BarcodeScanner } from '@ionic-native/barcode-scanner';

constructor(private barcodeScanner: BarcodeScanner) { }

...


this.barcodeScanner.scan().then((barcodeData) => {
 // Success! Barcode data is here
}, (err) => {
    // An error occurred
});

Instance Members

Encode

scan(options)

Open the barcode scanner.

Param Type Details
options BarcodeScannerOptions

Optional options to pass to the scanner

Returns: Promise<any> Returns a Promise that resolves with scanner data, or rejects with an error.

encode(type, data)

Encodes data into a barcode. NOTE: not well supported on Android

Param Type Details
type string

Type of encoding

data any

Data to encode

Returns: Promise<any>

BarcodeScannerOptions

Param Type Details
preferFrontCamera boolean

Prefer front camera. Supported on iOS and Android.

(optional)
showFlipCameraButton boolean

Show flip camera button. Supported on iOS and Android.

(optional)
showTorchButton boolean

Show torch button. Supported on iOS and Android.

(optional)
disableAnimations boolean

Disable animations. Supported on iOS only.

(optional)
disableSuccessBeep boolean

Disable success beep. Supported on iOS only.

(optional)
prompt string

Prompt text. Supported on Android only.

(optional)
formats string

Formats separated by commas. Defaults to all formats except PDF_417 and RSS_EXPANDED.

(optional)
orientation string

Orientation. Supported on Android only. Can be set to portrait or landscape. Defaults to none so the user can rotate the phone and pick an orientation.

(optional)
torchOn boolean

Launch with the torch switched on (if available). Supported on Android only.

(optional)
resultDisplayDuration number

Display scanned text for X ms. 0 suppresses it entirely, default 1500. Supported on Android only.

(optional)

BarcodeScanResult

Param Type Details
format 'QR_CODE' | 'DATA_MATRIX' | 'UPC_E' | 'UPC_A' | 'EAN_8' | 'EAN_13' | 'CODE_128' | 'CODE_39' | 'CODE_93' | 'CODABAR' | 'ITF' | 'RSS14' | 'RSS_EXPANDED' | 'PDF417' | 'AZTEC' | 'MSI'
cancelled boolean
text string

API

Native

General