UNPKG

6.13 kBMarkdownView Raw
1# PhoneGap Plugin BarcodeScanner
2================================
3
4[![Build Status](https://travis-ci.org/phonegap/phonegap-plugin-barcodescanner.svg)](https://travis-ci.org/phonegap/phonegap-plugin-barcodescanner)
5
6Cross-platform BarcodeScanner for Cordova / PhoneGap.
7
8Follows the [Cordova Plugin spec](http://cordova.apache.org/docs/en/5.0.0/plugin_ref_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).
9
10## Installation
11
12
13This requires phonegap 5.0+ ( current stable v3.0.0 )
14
15 phonegap plugin add phonegap-plugin-barcodescanner
16
17Older versions of phonegap can still install via the __deprecated__ id ( stale v2.0.1 )
18
19 phonegap plugin add com.phonegap.plugins.barcodescanner
20
21It is also possible to install via repo url directly ( unstable )
22
23 phonegap plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git
24
25### Supported Platforms
26
27- Android
28- iOS
29- Windows (Windows/Windows Phone 8.1 and Windows 10)
30- Windows Phone 8
31- BlackBerry 10
32- Browser
33
34Note: the Android source for this project includes an Android Library Project.
35plugman currently doesn't support Library Project refs, so its been
36prebuilt as a jar library. Any updates to the Library Project should be
37committed with an updated jar.
38
39Note: 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):
40
41```
42cordova run windows -- --archs=x86
43```
44
45### PhoneGap Build
46If you're using [PhoneGap Build](https://build.phonegap.com/) please make sure you specify `gradle` as your Android build tool in `config.xml`: `<preference name="android-build-tool" value="gradle" />`.
47
48## Using the plugin ##
49The plugin creates the object `cordova/plugin/BarcodeScanner` with the method `scan(success, fail)`.
50
51The following barcode types are currently supported:
52### Android
53
54* QR_CODE
55* DATA_MATRIX
56* UPC_E
57* UPC_A
58* EAN_8
59* EAN_13
60* CODE_128
61* CODE_39
62* CODE_93
63* CODABAR
64* ITF
65* RSS14
66* RSS_EXPANDED
67
68Not by default, but supported if you pass in the "formats" option:
69* PDF417
70* AZTEC
71
72### iOS
73
74* QR_CODE
75* DATA_MATRIX
76* UPC_E
77* UPC_A
78* EAN_8
79* EAN_13
80* CODE_128
81* CODE_39
82* ITF
83
84### Windows
85
86* UPC_A
87* UPC_E
88* EAN_8
89* EAN_13
90* CODE_39
91* CODE_93
92* CODE_128
93* ITF
94* CODABAR
95* MSI
96* RSS14
97* QR_CODE
98* DATA_MATRIX
99* AZTEC
100* PDF417
101
102### Windows Phone 8
103
104* UPC_A
105* UPC_E
106* EAN_8
107* EAN_13
108* CODE_39
109* CODE_93
110* CODE_128
111* ITF
112* CODABAR
113* MSI
114* RSS14
115* QR_CODE
116* DATA_MATRIX
117* AZTEC
118* PDF417
119
120### BlackBerry 10
121* UPC_A
122* UPC_E
123* EAN_8
124* EAN_13
125* CODE_39
126* CODE_128
127* ITF
128* DATA_MATRIX
129* AZTEC
130
131`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.
132
133A full example could be:
134```js
135 cordova.plugins.barcodeScanner.scan(
136 function (result) {
137 alert("We got a barcode\n" +
138 "Result: " + result.text + "\n" +
139 "Format: " + result.format + "\n" +
140 "Cancelled: " + result.cancelled);
141 },
142 function (error) {
143 alert("Scanning failed: " + error);
144 },
145 {
146 "preferFrontCamera" : true, // iOS and Android
147 "showFlipCameraButton" : true, // iOS and Android
148 "prompt" : "Place a barcode inside the scan area", // supported on Android only
149 "formats" : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
150 "orientation" : "landscape" // Android only (portrait|landscape), default unset so it rotates with the device
151 }
152 );
153```
154
155## Encoding a Barcode ##
156
157The plugin creates the object `cordova.plugins.barcodeScanner` with the method `encode(type, data, success, fail)`.
158
159Supported encoding types:
160
161* TEXT_TYPE
162* EMAIL_TYPE
163* PHONE_TYPE
164* SMS_TYPE
165
166```
167A full example could be:
168
169 cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
170 alert("encode success: " + success);
171 }, function(fail) {
172 alert("encoding failed: " + fail);
173 }
174 );
175```
176
177## Windows quirks ##
178Windows implementation currently doesn't support encode functionality.
179
180## Windows Phone 8 quirks ##
181Windows Phone 8 implementation currently doesn't support encode functionality.
182
183## BlackBerry 10 quirks
184BlackBerry 10 implementation currently doesn't support encode functionality.
185Cancelling a scan on BlackBerry 10 is done by touching the screen.
186
187## Thanks on Github ##
188
189So many -- check out the original [iOS](https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/iOS/BarcodeScanner), [Android](https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/Android/BarcodeScanner) and
190[BlackBerry 10](https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10-Cordova/BarcodeScanner) repos.
191
192## Licence ##
193
194The MIT License
195
196Copyright (c) 2010 Matt Kane
197
198Permission is hereby granted, free of charge, to any person obtaining a copy
199of this software and associated documentation files (the "Software"), to deal
200in the Software without restriction, including without limitation the rights
201to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
202copies of the Software, and to permit persons to whom the Software is
203furnished to do so, subject to the following conditions:
204
205The above copyright notice and this permission notice shall be included in
206all copies or substantial portions of the Software.
207
208THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
209IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
210FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
211AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
212LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
213OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
214THE SOFTWARE.