Skip to main content

Barcode Scan

The Docutain SDK comes with integrated, ready to use UI components for the barcode scan process.


Supported Barcode Formats

  • code128
  • code39
  • code93
  • codabar
  • ean13
  • ean8
  • itf
  • upca
  • upce
  • qr
  • pdf417
  • aztec
  • datamatrix


Initialize the Docutain SDK as described here.

Camera Permission

Declare the following permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name=""/>

Runtime permission for camera is handled automatically by the Docutain SDK.

Start the barcode scanner

To start the barcode scan process you only have to launch an ActivityResultLauncher with our predefined BarcodeScanResultContract contract and wait for it to return.

import de.docutain.sdk.barcode.contracts.BarcodeScanResultContract

val barcodeScanResultLauncher = registerForActivityResult(BarcodeScanResultContract()) { barcode ->
if (barcode != null) {
//user finished scan process, continue with your workflow
//val value = barcode.displayValue
//val format = barcode.format
} else {
//user canceled scan process

myButton.setOnClickListener {
val scanConfig = BarcodeScannerConfiguration()

An instance of BarcodeScannerConfiguration is required to launch the barcode scanner. It provides the possibility to change some behaviours to adopt it to your needs.

val scanConfig = BarcodeScannerConfiguration()
scanConfig.vibrateOnSuccess = false //defaults to true
scanConfig.beepOnSuccess = true //defaults to false
scanConfig.codeFormats = listOf(BarcodeFormat.CODE_39, BarcodeFormat.DATA_MATRIX) //defaults to all supported barcode formats
//more configs available

If you need to scan only specific barcode formats, you can improve the barcode scan performance by defining the barcode formats by setting scanConfig.codeFormats like in the example above.


All parameters in BarcodeScannerConfiguration are optional.