Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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