Barcode Scanner
Allows your mobile application to use the camera to scan QR codes, EAN-13 and other kinds of barcodes.
Supported Platforms
- Android
- iOS
Setup
This plugin requires a Rust version of at least 1.64
Install the barcode-scanner plugin to get started.
Use your project’s package manager to add the dependency:
npm run tauri add barcode-scanneryarn run tauri add barcode-scannerpnpm tauri add barcode-scannerbun tauri add barcode-scannercargo tauri add barcode-scanner-
Run
cargo add tauri-plugin-barcode-scannerto add the plugin to the project’s dependencies inCargo.toml. -
Modify
lib.rsto initialize the plugin:lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]fn run() {tauri::Builder::default().plugin(tauri_plugin_barcode_scanner::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
Install the JavaScript Guest bindings using your preferred JavaScript package manager:
npm install @tauri-apps/plugin-barcode-scanneryarn add @tauri-apps/plugin-barcode-scannerpnpm add @tauri-apps/plugin-barcode-scannerbun add @tauri-apps/plugin-barcode-scanner
Usage
The barcode scanner plugin is available in JavaScript.
import { scan, Format } from '@tauri-apps/plugin-barcode-scanner';// when using `"withGlobalTauri": true`, you may use// const { scan, Format } = window.__TAURI_PLUGIN_BARCODE_SCANNER__;
// `windowed: true` actually sets the webview to transparent// instead of opening a separate view for the camera// make sure your user interface is ready to show what is underneath with a transparent elementscan({ windowed: true, formats: [Format.QRCode] });Permissions
By default all plugin commands are blocked and cannot be accessed.
You must define a list of permissions in your capabilities configuration.
See Permissions Overview for more information.
{ "$schema": "../gen/schemas/mobile-schema.json", "identifier": "mobile-capability", "windows": ["main"], "platforms": ["iOS", "android"], "permissions": ["barcode-scanner:allow-scan", "barcode-scanner:allow-cancel"]}Default Permission
This permission set configures which barcode scanning features are by default exposed.
Granted Permissions
It allows all barcode related features.
allow-cancelallow-check-permissionsallow-open-app-settingsallow-request-permissionsallow-scanallow-vibrate
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the cancel command without any pre-configured scope. |
|
|
Denies the cancel command without any pre-configured scope. |
|
|
Enables the check_permissions command without any pre-configured scope. |
|
|
Denies the check_permissions command without any pre-configured scope. |
|
|
Enables the open_app_settings command without any pre-configured scope. |
|
|
Denies the open_app_settings command without any pre-configured scope. |
|
|
Enables the request_permissions command without any pre-configured scope. |
|
|
Denies the request_permissions command without any pre-configured scope. |
|
|
Enables the scan command without any pre-configured scope. |
|
|
Denies the scan command without any pre-configured scope. |
|
|
Enables the vibrate command without any pre-configured scope. |
|
|
Denies the vibrate command without any pre-configured scope. |
© 2024 Tauri Contributors. CC-BY / MIT