Jetpack compose Barcode/QR code scanner
Jetpack compose Barcode QR code scanner using Google’s ML Kit and CameraX. In this article, we’ll discover how to build a jetpack compose Barcode scanner using Google the ML Kit and Jetpack CameraX.
This is the first version of ML Kit as a standalone SDK that is independent of Firebase. The SDK includes all of the on-device APIs previously available through Firebase’s ML Kit for Firebase SDK. See ML Kit Release Notes.
A stand-alone library to run ML on your device that you can use in conjunction with without Firebase. Jetpack compose Barcode QR code scanner
What’s jetpack CameraX?
CameraX is a Jetpack support library that was designed to make the development of camera apps simpler. It provides a consistent and easy-to-use API surface that works across most Android devices, with backward compatibility to Android 5.0 (API level 21). While it leverages the capabilities of camera2, it uses a simpler, use the case-based approach that is lifecycle-aware.
What’s Google ML Kit?
ML Kit brings Google’s machine learning capabilities to mobile developers with an easy-to-use and powerful package. Create iOS and Android apps more interesting personal, efficient, and useful with tools that are designed for use on mobile devices.
ML Kit’s Barcode Scanner API ( Barcode QR code scanner )
Through ML Kit’s barcode scanning API, you are able to scan data encoded with the most commonly used barcode formats. Barcode scanning is performed within the device, and doesn’t require a connection.
Jetpack compose Barcode QR code scanner Example
Let’s Start your Android Studio and create a new android project with -> Select the jetpack Compose Activity.
After the finish, the steps and wait to build your project after successfully building add the below dependency in your Gradle Build.
Adding jetpack composes Camerax dependency.
def camerax_version = "1.0.2"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha29"
Adding BarCode Scanner MLKit Dependency.
//Barcode
implementation 'com.google.mlkit:barcode-scanning:17.0.0'
Adding Camera Permission dependency
//Camera Permission
implementation "com.google.accompanist:accompanist-permissions:0.19.0"