• This repository has been archived on 11/Aug/2020
  • Stars
    star
    1,271
  • Rank 36,067 (Top 0.8 %)
  • Language Objective-C++
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

cross-platform BarcodeScanner for Cordova / PhoneGap

PhoneGap Plugin BarcodeScanner

================================

Build Status

Cross-platform BarcodeScanner for Cordova / PhoneGap.

Follows the Cordova Plugin spec, so that it works with Plugman.

Installation

This requires phonegap 7.1.0+ ( current stable v8.0.0 )

phonegap plugin add phonegap-plugin-barcodescanner

It is also possible to install via repo url directly ( unstable )

phonegap plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git

Optional variables: This plugin requires the Android support library v4. The minimum version is 24.1.0. Default value is 27.+. Check out the latest version here.

phonegap plugin add phonegap-plugin-barcodescanner --variable ANDROID_SUPPORT_V4_VERSION="27.1.1"

Supported Platforms

  • Android
  • iOS
  • Windows (Windows/Windows Phone 8.1 and Windows 10)
  • Browser

Note: the Android source for this project includes an Android Library Project. plugman currently doesn't support Library Project refs, so its been prebuilt as a jar library. Any updates to the Library Project should be committed with an updated jar.

Note: Windows 10 applications can not be build for AnyCPU architecture, which is default for Windows platform. If you want to build/run Windows 10 app, you should specify target architecture explicitly, for example (Cordova CLI):

cordova run windows -- --archs=x86

PhoneGap Build Usage

Add the following to your config.xml:

<!-- add a version here, otherwise PGB will use whatever the latest version of the package on npm is -->
<plugin name="phonegap-plugin-barcodescanner" />

On PhoneGap Build if you're using a version of cordova-android of 4 or less, ensure you're building with gradle:

<preference name="android-build-tool" value="gradle" />

Using the plugin

The plugin creates the object cordova.plugins.barcodeScanner with the method scan(success, fail).

The following barcode types are currently supported:

Barcode Type Android iOS Windows
QR_CODE ✔ ✔ ✔
DATA_MATRIX ✔ ✔ ✔
UPC_A ✔ ✔ ✔
UPC_E ✔ ✔ ✔
EAN_8 ✔ ✔ ✔
EAN_13 ✔ ✔ ✔
CODE_39 ✔ ✔ ✔
CODE_93 ✔ ✔ ✔
CODE_128 ✔ ✔ ✔
CODABAR ✔ ✖ ✔
ITF ✔ ✔ ✔
RSS14 ✔ ✖ ✔
PDF_417 ✔ ✔ ✔
RSS_EXPANDED ✔ ✖ ✖
MSI ✖ ✖ ✔
AZTEC ✔ ✔ ✔

success and fail are callback functions. Success is passed an object with data, type and cancelled properties. Data is the text representation of the barcode data, type is the type of barcode detected and cancelled is whether or not the user cancelled the scan.

A full example could be:

   cordova.plugins.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 : true, // iOS and Android
          showFlipCameraButton : true, // iOS and Android
          showTorchButton : true, // iOS and Android
          torchOn: true, // Android, launch with the torch switched on (if available)
          saveHistory: true, // Android, save scan history (default false)
          prompt : "Place a barcode inside the scan area", // 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
      }
   );

Encoding a Barcode

The plugin creates the object cordova.plugins.barcodeScanner with the method encode(type, data, success, fail).

Supported encoding types:

  • TEXT_TYPE
  • EMAIL_TYPE
  • PHONE_TYPE
  • SMS_TYPE
A full example could be:

   cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
            alert("encode success: " + success);
          }, function(fail) {
            alert("encoding failed: " + fail);
          }
        );

iOS quirks

Since iOS 10 it's mandatory to add a NSCameraUsageDescription in the Info.plist.

NSCameraUsageDescription describes the reason that the app accesses the user's camera. When the system prompts the user to allow access, this string is displayed as part of the dialog box. If you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide an usage description.

To add this entry you can use the edit-config tag in the config.xml like this:

<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
    <string>To scan barcodes</string>
</edit-config>

Windows quirks

  • Windows implementation currently doesn't support encode functionality.

  • On Windows 10 desktop ensure that you have Windows Media Player and Media Feature pack installed.

Thanks on Github

So many -- check out the original iOS, Android and BlackBerry 10 repos.

Licence

The MIT License

Copyright (c) 2010 Matt Kane

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

phonegap-start

PhoneGap Hello World app
JavaScript
3,421
star
2

phonegap-app-developer

PhoneGap Developer App
JavaScript
1,998
star
3

phonegap-plugin-push

Register and receive push notifications
Java
1,942
star
4

phonegap-app-desktop

PhoneGap Desktop App
JavaScript
842
star
5

phonegap-cli

PhoneGap and PhoneGap/Build command-line interface
JavaScript
489
star
6

phonegap-plugin-contentsync

Download and cache remotely hosted content
C
206
star
7

phonegap-plugin-fast-canvas

Fast, 2D, mostly-HTML5-canvas-compatible rendering surface for Android.
C
196
star
8

phonegap-mobile-accessibility

PhoneGap plugin to expose mobile accessibility APIs.
JavaScript
146
star
9

phonegap-docs

PhoneGap Documentation
Pug
121
star
10

build

This is the public repository for PhoneGap Build source and bug tracking
92
star
11

phonegap-community

PhoneGap Community Release Notes
81
star
12

phonegap-template-react-hot-loader

PhoneGap Template using React, ES2015, Webpack, and hot module reloading
JavaScript
79
star
13

phonegap-template-hello-world

PhoneGap Hello World app
JavaScript
72
star
14

node-phonegap-build-api

Node.js REST Client for the PhoneGap Build API
JavaScript
62
star
15

connect-phonegap

Stream a PhoneGap app to any device.
JavaScript
61
star
16

phonegap-app-star-track

The PhoneGap media example app
CSS
54
star
17

phonegap-plugin-pwa

A plugin to provide progressive web app API's
45
star
18

phonegap-template-framework7

A starter template for creating a hybrid app with Framework7.
CSS
43
star
19

phonegap-app-anyconference

AnyConference example app
JavaScript
41
star
20

phonegap-2-style-3

PhoneGap 3.0 project that includes all of the plugins by default
JavaScript
39
star
21

phonegap-plugin-local-notification

An implementation of the Web Notifications API for end-user notifications.
Objective-C
38
star
22

phonegap-webview-ios

Native iOS + PhoneGap Template
Ruby
36
star
23

phonegap-plugin-media-stream

JavaScript
34
star
24

phonegap-template-vue-f7-blank

A blank PhoneGap template using Vue.js and Framework7
JavaScript
32
star
25

phonegap-template-vue-f7-tabs

A TabBar PhoneGap template using Vue.js and Framework7
JavaScript
31
star
26

phonegap-symbian.wrt

Symbian WRT implementation of the PhoneGap API
JavaScript
28
star
27

emulate.phonegap.com

Ripple emulation for PhoneGap's JavaScript environment
JavaScript
28
star
28

node-phonegap-build

PhoneGap Build node module to login, create, and build apps.
JavaScript
26
star
29

phonegap-sample-hybrid-ios

A sample application showing a hybrid application with both native and webview components and communication.
Objective-C
24
star
30

phonegap-sample-hybrid-android

Java
22
star
31

phonegap-app-fast-canvas

Example game using phonegap-fast-canvas-plugin
JavaScript
20
star
32

phonegap.github.io

Main pages for phonegap.com hosted on GitHub pages.
JavaScript
20
star
33

phonegap-plugin-multiview

Spawn multiple cordova enabled webviews in one app
JavaScript
18
star
34

phonegap-template-vue-f7-split-panel

A Split View PhoneGap template using Vue.js and Framework7 that degrades to a Panel View on smaller devices
JavaScript
16
star
35

phonegap-plugin-media-recorder

Objective-C
14
star
36

phonegap-plugin-image-capture

JavaScript
11
star
37

build-bot-model

PhoneGap Build Bot 3D model
11
star
38

phonegap-plugin-template

This repo is a template for starting a new plugin.
JavaScript
10
star
39

phonegap-template-push

A sample application for getting started with push notifications
JavaScript
8
star
40

app

The app showcase found at http://phonegap.github.io/app
HTML
7
star
41

app.phonegap.com

Micro-site for the PhoneGap Developer App and PhoneGap Desktop app.
JavaScript
7
star
42

phonegap-app-anyconference-pgday

AnyConference app for PhoneGap Day
JavaScript
7
star
43

phonegap-app-augmented-reality

CSS
6
star
44

phonegap-template-vue-f7-todos-pwa

A Todo's app template with PWA support using Vue.js and Framework7
JavaScript
6
star
45

adobe-creative-sdk-foundation

OBSOLETE - see README
4
star
46

phonegap-roadmap

Upcoming milestones and projects for PhoneGap
4
star
47

native-plugin-sync-demo

Demo of native-plugin-sync
CSS
4
star
48

book

http://phonegap.com/book/
HTML
3
star
49

workshop-plugins

Workshop / lab content covering end to end plugin development
3
star
50

phonegap-plugin-multidex

Enable multidex in a Apache Cordova/PhoneGap application
3
star
51

tool

A collection of 3rd party tools for PhoneGap development.
HTML
3
star
52

cordova-android

DO NOT DELETE - contains the thread-safe bridge code
Java
3
star
53

phonegap-app-stockpile

n. - A storage pile accumulated for future use
JavaScript
3
star
54

phonegap-template-blank

A blank PhoneGap app.
HTML
3
star
55

phonegap-day

The website for PhoneGap Day
JavaScript
2
star
56

phonegap-app-todo

JavaScript
2
star
57

linting-and-editorconfig

Reference repo for eslint (and other linters) as well as editorconfig settings and info
JavaScript
1
star
58

topcoat-preact

React components implementing Topcoat components
JavaScript
1
star
59

phonegap-template-webvr

PhoneGap template for the WebVR Boilerplate at https://github.com/borismus/webvr-boilerplate
JavaScript
1
star
60

dotfiles

A repo to collect the dot files we use consistently in our other repositories
1
star
61

phonegap-plugin-developer-mode

Utility functions for the Phonegap Developer app
JavaScript
1
star