Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support barcode scanner #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions docs/_plugins/barcodescanner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: BarcodeScanner
add_url: cordova-plugin-barcodescanner
description: Access the barcodescanner plugin
---

The Barcode Scanner is made available in `Vue.cordova.barcodeScanner`. You may then access the two functions to scan and encode barcodes.

Works with `cordova-plugin-barcodescanner` and the better `phonegap-plugin-barcodescanner` (which supports configuration options as third argument in the scan function and works also on Android API level >=23)

###### Sample code
With the `phonegap-plugin-barcodescanner`:
```javascript
Vue.cordova.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)
},
{
preferFrontCamera: false, // iOS and Android
showFlipCameraButton: true, // iOS and Android
showTorchButton: true, // iOS and Android
torchOn: false, // Android, launch with the torch switched on (if available)
saveHistory: false, // Android, save scan history (default false)
prompt: 'Scan a barcode', // Android
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
// formats: 'QR_CODE,PDF_417', // default: all but PDF_417 and RSS_EXPANDED
// orientation: 'landscape', // Android only (portrait|landscape), default unset so it rotates with the device
disableAnimations: true, // iOS
disableSuccessBeep: false // iOS and Android
}
)
}
```

With the `cordova-plugin-barcodescanner`:
```javascript
Vue.cordova.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)
}
)
}
```

###### Install

```bash
cordova plugin add phonegap-plugin-barcodescanner
```
or
```bash
cordova plugin add cordova-plugin-barcodescanner
```

###### Source

<a href="https://www.npmjs.com/package/phonegap-plugin-barcodescanner" target="_blank" class="icon npm">phonegap-plugin-barcodescanner</a>

<a href="https://www.npmjs.com/package/cordova-plugin-barcodescanner" target="_blank" class="icon npm">cordova-plugin-barcodescanner</a>
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const pluginsList = [
'cordova-plugin-geolocation',
'cordova-plugin-contacts',
'cordova-plugin-chrome-apps-sockets-tcp',
'cordova-plugin-sms'
'cordova-plugin-sms',
'cordova-plugin-barcodescanner'
]

exports.install = (Vue, options) => {
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/cordova-plugin-barcodescanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.install = function (Vue, options, cb) {
document.addEventListener('deviceready', () => {

if (typeof window.cordova.plugins.barcodeScanner === 'undefined') {
return cb(false)
}

// pass through the barcodeScanner object
Vue.cordova.barcodeScanner = window.cordova.plugins.barcodeScanner

return cb(true)

}, false)
}