QR Code Scanner for Android
QR Code Scanner for Android built by Ubique based on AndroidX Camera2 with support for ZXing or MLKit decoding.
Download
This library is available on mavenCentral()
implementation 'ch.ubique.android:qrscanner-core:1.0.0'
implementation 'ch.ubique.android:qrscanner-zxing:1.0.0'
implementation 'ch.ubique.android:qrscanner-mlkit:1.0.0'
implementation 'ch.ubique.android:qrscanner-compose:1.0.0'
Quick Start
Check out the example app included in this repository on how to use the library.
Note: Camera permission handling is not handled by the library, it is the responsibility of the client app to request the permission.
Android View
Include the view in your layout:
<ch.ubique.qrscanner.view.QrScannerView
android:id="@+id/qrScanner"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Define the image decoders to be used to scan for QR codes:
qrScanner.setImageDecoders(
MLKitImageDecoder(),
GlobalHistogramImageDecoder(),
HybridImageDecoder(),
)
Set a callback for the decoding state:
qrScanner.setScannercallback { state ->
when (state) {
is DecodingState.NotFound -> {}
is DecodingState.Decoded -> {}
is DecodingState.Error -> {}
}
}
Optional settings:
qrScanner.setFlash(false)
qrScanner.setLinearZoom(0f)
qrScanner.setFocusOnTap(true)
qrScanner.setScanningMode(ScanningMode.PARALLEL)
Jetpack Compose
Invoke the composable in your screen:
QrScanner(
imageDecoders = listOf(
MLKitImageDecoder(),
GlobalHistogramImageDecoder(),
HybridImageDecoder(),
),
scannerCallback = QrScannerCallback { state ->
when (state) {
is DecodingState.NotFound -> {}
is DecodingState.Decoded -> {}
is DecodingState.Error -> {}
}
},
modifier = Modifier.fillMaxSize(),
scanningMode = ScanningMode.PARALLEL,
isFlashEnabled = remember { mutableStateOf(false) },
linearZoom = remember { mutableStateOf(0f) },
)
License
This project is licensed under the terms of the MPL 2 license. See the LICENSE file for details.