Barcode Scanner
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
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add phonegap-plugin-barcodescanner $ npm install --save @ionic-native/barcode-scanner@4 - Add this plugin to your app's module
Supported platforms
- Android
- BlackBerry 10
- Browser
- iOS
- Windows
Usage
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
constructor(private barcodeScanner: BarcodeScanner) { }
...
this.barcodeScanner.scan().then(barcodeData => {
console.log('Barcode data', barcodeData);
}).catch(err => {
console.log('Error', err);
});
Instance Members
Encode
scan(options)
Open the barcode scanner.
| Param | Type | Details |
|---|---|---|
| options |
BarcodeScannerOptions
|
Optional options to pass to the scannerOptional |
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 |
| orientation |
string
|
Orientation. Supported on Android only. Can be set to |
| 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'
| 'PDF_417'
| 'AZTEC'
| 'MSI'
|
|
| cancelled |
boolean
|
|
| text |
string
|