Google code scanner API — scanning codes without camera permission

Google code scanner view
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}
dependencies {
implementation 'com.google.android.gms:play-services-code-scanner:16.0.0-beta1'
}
<application ...>
...
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode_ui"/>
...
</application>
//**** java ****
GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder()
.setBarcodeFormats(
Barcode.FORMAT_QR_CODE,
Barcode.FORMAT_AZTEC)
.build();
//**** kotlin ****
val options = GmsBarcodeScannerOptions.Builder()
.setBarcodeFormats(
Barcode.FORMAT_QR_CODE,
Barcode.FORMAT_AZTEC
)
.build()
//**** java ****
GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(this);
// Or with a configured options
// GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(context, options);
//**** kotlin ****
val scanner = GmsBarcodeScanning.getClient(this)
// Or with a configured options
// val scanner = GmsBarcodeScanning.getClient(this, options)
//**** java ****
scanner
.startScan()
.addOnSuccessListener(
barcode -> {
// Task completed successfully
})
.addOnFailureListener(
e -> {
// Task failed with an exception
});
//**** kotlin ****
scanner.startScan()
.addOnSuccessListener { barcode ->
// Task completed successfully
}
.addOnFailureListener { e ->
// Task failed with an exception
}
//**** java ****
String rawValue = barcode.getRawValue();
//**** kotlin ****
val rawValue: String? = barcode.rawValue

--

--

Mobile Engineer, UI/UX. I believe in the quote, “Creativity is thinking up new things. Innovation is doing new things.” Happy Coding :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prabhakar Thota

Mobile Engineer, UI/UX. I believe in the quote, “Creativity is thinking up new things. Innovation is doing new things.” Happy Coding :)