Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed May 2, 2016
1 parent 55b716a commit f0ad027
Show file tree
Hide file tree
Showing 12 changed files with 1,738 additions and 136 deletions.
164 changes: 108 additions & 56 deletions README.md
@@ -1,14 +1,46 @@
BarcodeScanner
==============
# PhoneGap Plugin BarcodeScanner
================================

Added version that runs with windows mobile devices.
To run on those devices, the zxing.net library must be added to the project (Install as nuget packet - more information on http://www.nuget.org/packages/ZXing.Net)

Windows Phone currently only supports Scaning for codes, feel free to extend it that it can also encode.
[![Build Status](https://travis-ci.org/phonegap/phonegap-plugin-barcodescanner.svg)](https://travis-ci.org/phonegap/phonegap-plugin-barcodescanner)

Cross-platform BarcodeScanner for Cordova / PhoneGap.

Follows the [Cordova Plugin spec](https://github.com/apache/cordova-plugman/blob/master/plugin_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).
Follows 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).

## Installation


This requires phonegap 5.0+ ( current stable v3.0.0 )

phonegap plugin add phonegap-plugin-barcodescanner

Older versions of phonegap can still install via the __deprecated__ id ( stale v2.0.1 )

phonegap plugin add com.phonegap.plugins.barcodescanner

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

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

### Supported Platforms

- Android
- iOS
- Windows (Windows/Windows Phone 8.1 and Windows 10)
- Windows Phone 8
- BlackBerry 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
```

## Using the plugin ##
The plugin creates the object `cordova/plugin/BarcodeScanner` with the method `scan(success, fail)`.
Expand Down Expand Up @@ -46,17 +78,54 @@ Not by default, but supported if you pass in the "formats" option:
* CODE_39
* ITF

`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.
### Windows

* UPC_A
* UPC_E
* EAN_8
* EAN_13
* CODE_39
* CODE_93
* CODE_128
* ITF
* CODABAR
* MSI
* RSS14
* QR_CODE
* DATA_MATRIX
* AZTEC
* PDF417

### Windows Phone 8

On iOS and Android you can pass in options (ignored on WP8):
* `preferFrontCamera` default false: prefer starting the scanner with the front camera (if multiple cameras are available).
* `showFlipCameraButton` default false: show a button on the scan UI to toggle the back/front camera (if multiple cameras are available).
* UPC_A
* UPC_E
* EAN_8
* EAN_13
* CODE_39
* CODE_93
* CODE_128
* ITF
* CODABAR
* MSI
* RSS14
* QR_CODE
* DATA_MATRIX
* AZTEC
* PDF417

And on Android you can also pass in these:
* `prompt` default: Place a barcode inside the viewfinder rectangle to scan it.
* `formats` default: all but PDF_417 and RSS_EXPANDED
* `orientation` lock the orientation to "portrait" or "landscape". By default the scan view rotates with the device orientation.
### BlackBerry 10
* UPC_A
* UPC_E
* EAN_8
* EAN_13
* CODE_39
* CODE_128
* ITF
* DATA_MATRIX
* 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:
```js
Expand All @@ -71,68 +140,51 @@ A full example could be:
alert("Scanning failed: " + error);
},
{
"preferFrontCamera" : true,
"showFlipCameraButton" : true,
"preferFrontCamera" : true, // iOS and Android
"showFlipCameraButton" : true, // iOS and Android
"prompt" : "Place a barcode inside the scan area", // supported on Android only
"formats" : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
"orientation" : "landscape"
}
);
```

## Checking permission
On Android 6 you need to request permission to use the camera at runtime when targeting API level 23+.
Even if the `uses-permission` tag for the Camera is present in `AndroidManifest.xml`.

Note that `hasCameraPermission` will return true when:
* You're running this on iOS, or
* You're targeting an API level lower than 23, or
* You're using Android < 6, or
* You've already granted permission.

```js
function hasCameraPermission() {
cordova.plugins.barcodeScanner.hasCameraPermission(
function(result) {
// if this is 'false' you probably want to call 'requestCameraPermission' now
alert(result);
}
)
}

function requestCameraPermission() {
// no callbacks required as this opens a popup which returns async
cordova.plugins.barcodeScanner.requestCameraPermission();
}
```

Note that backward compatibility was added by checking for permission in the `scan` function.
If permission is needed the `scan` method will now show the permission request popup.
The user will then need to allow camera access and launch the scanner again.

## 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:
```JS
cordova.plugins.barcodeScanner.encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
alert("encode success: " + success);
}, function(fail) {
alert("encoding failed: " + fail);
}
);
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);
}
);
```

## Thanks on Github ##
## Windows quirks ##
Windows implementation currently doesn't support encode functionality.

## Windows Phone 8 quirks ##
Windows Phone 8 implementation currently doesn't support encode functionality.

So many -- check out the original [iOS](https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner) and [Android](https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner) repos.
## BlackBerry 10 quirks
BlackBerry 10 implementation currently doesn't support encode functionality.
Cancelling a scan on BlackBerry 10 is done by touching the screen.

## Thanks on Github ##

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
[BlackBerry 10](https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10-Cordova/BarcodeScanner) repos.

## Licence ##

Expand Down
44 changes: 44 additions & 0 deletions package.json
@@ -0,0 +1,44 @@
{
"name": "phonegap-plugin-barcodescanner",
"version": "4.1.0",
"description": "You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.",
"cordova": {
"id": "phonegap-plugin-barcodescanner",
"platforms": [
"ios",
"android",
"windows8",
"windows",
"wp8",
"blackberry10",
"browser"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner.git"
},
"keywords": [
"ecosystem:cordova",
"ecosystem:phonegap",
"cordova-ios",
"cordova-android",
"cordova-windows8",
"cordova-windows",
"cordova-wp8",
"cordova-blackberry10",
"cordova-browser"
],
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"author": "Adobe PhoneGap Team",
"license": "MIT",
"bugs": {
"url": "https://github.com/phonegap/phonegap-plugin-barcodescanner/issues"
},
"homepage": "https://github.com/phonegap/phonegap-plugin-barcodescanner#readme"
}
113 changes: 91 additions & 22 deletions plugin.xml
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?><plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.barcodescanner"
version="2.1.2">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:rim="http://www.blackberry.com/ns/widgets"
id="com.phonegap.plugins.barcodescanner"
version="4.1.0.1">

<name>BarcodeScanner</name>
<description>You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.</description>
<license>MIT</license>

<repo>https://github.com/phonegap/phonegap-plugin-barcodescanner</repo>
<issue>https://github.com/phonegap/phonegap-plugin-barcodescanner/issues</issue>

<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
Expand Down Expand Up @@ -38,25 +42,6 @@
<framework src="QuartzCore.framework" />
</platform>

<!-- wp8 -->
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="BarcodeScanner">
<param name="wp-package" value="BarcodeScanner"/>
</feature>
</config-file>

<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
<Capability Name="ID_CAP_ISV_CAMERA" />
</config-file>

<source-file src="src/wp8/BarcodeScanner.cs" />
<source-file src="src/wp8/BarcodeScannerResult.cs" />
<source-file src="src/wp8/Scan.xaml" />
<source-file src="src/wp8/Scan.xaml.cs" />
<framework src="src/wp8/zxing.wp8.0.dll" custom="true" />
</platform>

<!-- android -->
<platform name="android">

Expand Down Expand Up @@ -105,4 +90,88 @@
<framework src="src/android/barcodescanner.gradle" custom="true" type="gradleReference"/>
<resource-file src="src/android/barcodescanner-release-2.0.1.aar" target="libs/barcodescanner.aar" />
</platform>

<platform name="windows8">
<js-module src="src/windows/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<merges target="" />
</js-module>

<config-file target="package.appxmanifest" parent="/Package/Capabilities">
<DeviceCapability Name="webcam" />
</config-file>

<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference" versions="&lt;=8.1"/>
<framework src="src/windows/lib.UW/WinRTBarcodeReader.UW.csproj" custom="true" type="projectReference" versions=">8.1"/>

<asset src="src/windows/assets/plugin-barcodeScanner.css" target="css/plugin-barcodeScanner.css" />
</platform>

<platform name="windows">
<js-module src="src/windows/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<merges target="" />
</js-module>

<config-file target="package.appxmanifest" parent="/Package/Capabilities">
<DeviceCapability Name="webcam" />
</config-file>

<framework src="src/windows/lib.UW/x86/ZXing.winmd" target-dir="x86" arch="x86" custom="true" versions=">8.1" />
<framework src="src/windows/lib.UW/x64/ZXing.winmd" target-dir="x64" arch="x64" custom="true" versions=">8.1" />
<framework src="src/windows/lib.UW/ARM/ZXing.winmd" target-dir="ARM" arch="ARM" custom="true" versions=">8.1" />
<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference" versions="&lt;=8.1"/>

<asset src="src/windows/assets/plugin-barcodeScanner.css" target="css/plugin-barcodeScanner.css" />
</platform>

<!-- Windows Phone 8 -->
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="BarcodeScanner">
<param name="wp-package" value="BarcodeScanner"/>
</feature>
</config-file>

<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
<Capability Name="ID_CAP_ISV_CAMERA" />
</config-file>

<framework src="src/wp8/lib/zxing.wp8.0.dll" custom="true" />

<asset src="src/wp8/assets/cancel.png" target="Images/appbar.cancel.png" />

<source-file src="src/wp8/BarcodeScanner.cs" />
<source-file src="src/wp8/BarcodeScannerTask.cs" />
<source-file src="src/wp8/BarcodeScannerUI.xaml" />
<source-file src="src/wp8/BarcodeScannerUI.xaml.cs" />
</platform>

<!-- browser -->
<platform name="browser">
<config-file target="config.xml" parent="/*">
<feature name="BarcodeScanner">
<param name="browser-package" value="BarcodeScanner" />
</feature>
</config-file>

<js-module src="src/browser/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<runs />
</js-module>
</platform>

<!-- BlackBerry 10 -->
<platform name="blackberry10">
<source-file src="src/blackberry10/index.js" target-dir="BarcodeScanner" />
<source-file src="src/blackberry10/qrcode.js" target-dir="BarcodeScanner" />
<lib-file src="src/blackberry10/native/device/libBarcodeScanner.so" arch="device"/>
<lib-file src="src/blackberry10/native/simulator/libBarcodeScanner.so" arch="simulator"/>
<config-file target="www/config.xml" parent="/widget">
<feature name="BarcodeScanner">
<param name="blackberry-package" value="phonegap-plugin-barcodescanner" />
</feature>
</config-file>
<config-file target="www/config.xml" parent="/widget/rim:permissions">
<rim:permit>use_camera</rim:permit>
</config-file>
<dependency id="cordova-plugin-bb-app" />
</platform>
</plugin>

0 comments on commit f0ad027

Please sign in to comment.