Skip to content

Commit

Permalink
Merge pull request #16 from willhay/feature/android-platform
Browse files Browse the repository at this point in the history
Add android platform
  • Loading branch information
bitjson authored Aug 5, 2016
2 parents 886b170 + b15e06f commit 619acbc
Show file tree
Hide file tree
Showing 8 changed files with 810 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"copy-platform-tests": "ncp tests/project ../cordova-plugin-test-projects/cordova-plugin-qrscanner-tests",
"install-platform-tests": "cd ../cordova-plugin-test-projects/cordova-plugin-qrscanner-tests && npm install",
"test:ios": "cd ../cordova-plugin-test-projects/cordova-plugin-qrscanner-tests && npm run test:ios",
"test:android": "cd ../cordova-plugin-test-projects/cordova-plugin-qrscanner-tests && npm run test:android",
"test:browser": "cd ../cordova-plugin-test-projects/cordova-plugin-qrscanner-tests && npm run test:browser",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
},
Expand Down
16 changes: 16 additions & 0 deletions plugin.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
<clobbers target="QRScanner" />
</js-module>

<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="QRScanner">
<param name="android-package" value="com.bitpay.cordova.qrscanner.QRScanner"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.CAMERA" android:required="false" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
</config-file>
<source-file src="src/android/QRScanner.java" target-dir="src/com/bitpay/cordova/qrscanner"/>
<dependency id="cordova-plugin-compat" version="^1.0.0" />
<framework src="src/android/qrscanner.gradle" custom="true" type="gradleReference"/>
</platform>

<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="QRScanner">
Expand Down
24 changes: 20 additions & 4 deletions readme.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ QRScanner.pausePreview(function(status){
})
```

Pauses the video preview on the current frame (as if a snapshot was taken).
Pauses the video preview on the current frame (as if a snapshot was taken) and stops scanning (if scanning).

```js
QRScanner.resumePreview(function(status){
console.log(status);
})
```

Resumes the video preview.
Resumes the video preview and continues to scan (if scanning before pausePreview()).

### Open App Settings

Expand All @@ -228,7 +228,7 @@ QRScanner.getStatus(function(status){

Open the app-specific permission settings in the user's device settings. Here the user can enable/disable camera (and other) access for your app.

Note: iOS immediately kills all apps affected by permissions changes. If the user changes a permission settings, your app will stop and only restart when they return.
Note: iOS and Android (6.0+) immediately kill all apps affected by permissions changes. If the user changes a permission settings, your app will stop and only restart when they return.

### Get QRScanner Status

Expand Down Expand Up @@ -261,7 +261,7 @@ Retrieve the status of QRScanner and provide it to the callback function.
Name | Description
:------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
`authorized` | On iOS and Android 6.0+, camera access is granted at runtime by the user (by clicking "Allow" at the dialog). The `authorized` property is a boolean value which is true only when the user has allowed camera access to your app (`AVAuthorizationStatus.Authorized`). On platforms with permissions granted at install (Android pre-6.0, Windows Phone) this property is always true.
`denied` | A boolean value which is true if the user permenantly denied camera access to the app (`AVAuthorizationStatus.Denied`). Once denied, camera access can only be gained by requesting the user change their decision (consider offering a link to the setting via `openSettings()`).
`denied` | A boolean value which is true if the user permenantly denied camera access to the app (`AVAuthorizationStatus.Denied`). Once denied, camera access can only be gained by requesting the user change their decision (consider offering a link to the setting via `openSettings()`). On Android(6.0+), denied will remain false up until the user permanently denies camera permission by checking the `Never ask again` checkbox. Once checked, the user must be prompted to openSettings() in order to grant camera permissions at which point, if granted, denied will switch to false and authorized to true.
`restricted` | A boolean value which is true if the user is unable to grant permissions due to parental controls, organization security configuration profiles, or similar reasons.
`prepared` | A boolean value which is true if QRScanner is prepared to capture video and render it to the view.
`showing` | A boolean value which is true when the preview layer is visible (and on all platforms but `browser`, the native webview background is transparent).
Expand All @@ -273,6 +273,7 @@ Name | Description
`canChangeCamera` | A boolean value which is true only if the current device "should" have a front camera. The camera may still not be capturable, which would emit error code 3, 4, or 5 when the switch is attempted.
`currentCamera` | A number representing the index of the currentCamera. `0` is the back camera, `1` is the front.


### Destroy

```js
Expand Down Expand Up @@ -333,6 +334,18 @@ While the browser implementation matches the native mobile implementations very

The browser implementation of this plugin is designed to abstract these platform differences very thoroughly. It's recommended that you focus your development efforts on implementing this plugin well for one of the mobile platform, and the browser platform implementation will degrade gracefully from there.

## Android

Before testing with Android, please install [Java Development Kit (JDK) 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html), [Android Studio](https://developer.android.com/studio/index.html), and the SDK packages for whatever [API level](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) you wish to target.

Cordova's CLI tools require some environment variables to be set in order to function correctly. The CLI will attempt to set these variables for you, but in certain cases you may need to set them manually. Please refer to [Cordova's Android Platform Guide](https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html) for more information.

Please make sure you have Gradle updated. If you get an error stating "Gradle Version 2.10 is required", ensure you selected `Use default Gradle wrapper` when Android Studio started up. Then edit the `Project/gradle/wrapper/gradle-wrapper.properties` file and change the distributionUrl line to `distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-all.zip`.

Open the SDK manager in Android Studio and make sure you have latest Google Play Services SDK Tool installed.

When calling pausePreview() with the flash on the camera preview will pause and the flash will switch off. Call resumePreview() to resume the camera preview and activate the flash.

### Video Preview DOM Element

Unlike the other platforms, it's not possible to spawn the `<video>` preview behind the `<html>` and `<body>` using only Javascript. Trying to mimick the effect by making the element a sibling to either the `<html>` or `<body>` elements also produces inconsistent results (ie: no rendering on Chromium). Instead, this plugin appends the `<video>` element as the final child of the `<body>` element, and applies styling to cover the entire background.
Expand All @@ -359,6 +372,8 @@ If more cameras are available, the "front" camera is then chosen from the highes

The browser platform always returns the boolean `status.canEnableLight` as `false`, and the enableLight/disableLight methods throw the `LIGHT_UNAVAILABLE` error code.

`status.canEnableLight` is camera specific, meaning it will return `false` if the camera in use does not have a flash.

### Using with Electron or NW.js

This plugin should work out-of-the box with the Cordova browser platform. As of now, there is no clear "best-way" of using the cordova browser build inside an Electron or NW.js application. This plugin attempts to provide an as-clean-as-possible source such that implementations can choose to either:
Expand Down Expand Up @@ -396,6 +411,7 @@ This will create a new cordova project in the `cordova-plugin-test-projects` dir

- `npm run test:ios`
- `npm run test:browser`
- `npm run test:android`

Both Automatic Tests (via Cordova Plugin Test Framework's built-in [Jasmine](https://github.com/jasmine/jasmine)) and Manual Tests are available. Automatic tests confirm the existence and expected structure of the javascript API, and manual tests should be used to confirm functionality on each platform.

Expand Down
Loading

0 comments on commit 619acbc

Please sign in to comment.