QR/Barcode Reader Plugin (Premium)
This premium plugin integrates native QR code and barcode scanning functionality using the device’s camera.
This is a premium plugin and is not included in the open-source project. Its source code is only available to Project Sponsors.
Setup and Configuration
- Obtain the Plugin: Acquire the plugin files through a GitHub sponsorship.
- Add to Project: Place the
QRScannerPlugin.java
file in theplugins/
directory. - Enable Plugin: Ensure the plugin is enabled in
SmartWebView.java
:put("QRScannerPlugin", true);
- Dependencies: The plugin relies on the
zxing-android-embedded
library. Ensure this dependency is present in yourapp/build.gradle
file:implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
- Camera Permission: The app already requests the
CAMERA
permission, which this plugin requires.
Usage
The plugin is controlled via a JavaScript interface.
Starting a Scan from JavaScript
The plugin injects a window.QRScanner
object into your web page.
// Open the camera and start scanning for a code
window.QRScanner.scan();
Callbacks in JavaScript
Define callback functions in your JavaScript to handle the results of the scan.
// Called when a code is successfully scanned
window.QRScanner.onScanSuccess = function(contents) {
console.log('Scanned content:', contents);
alert('Scanned: ' + contents);
// Process the scanned data in your web app
};
// Called if the user cancels the scan (e.g., by pressing the back button)
window.QRScanner.onScanCancelled = function() {
console.log('Scan was cancelled by the user.');
};