Skip to main content

Using Barcode Scanner | Android Document Scanner

The Scanbot SDK provides the ability to scan and extract content from barcodes and QR codes.


See our Example Apps on how to integrate the barcode scanner.

πŸ’‘ You might also be interested in an overview in our blog post Types of barcodes.

Data parsers#

The following data parsers are currently supported:

  • AAMVA: Parse the AAMVA data format from PDF-417 barcodes on US driver’s licenses. See AAMVADocument.
  • Boarding pass data from PDF-417 barcodes. See BoardingPassDocument.
  • Parser for German Medical Certificates (aka. Disability Certificate or AU-Bescheinigung) coded in a PDF-417 barcode. See DEMedicalPlanDocument.
  • Data from PDF-417 barcodes on ID Cards. See IDCardPDF417Document.
  • Parse and extract data from XML of Data Matrix barcodes on Medical Plans (German Medikationsplan).
  • Data parser of QR-Code values printed on SEPA pay forms. See SEPADocument.
  • vCard data from a QR-Code (e.g. on business cards). See VCardDocument.
  • Swiss QR data from a QR-Code. See SwissQRDocument.

Tuning the Android Manifest#

Camera Permission#

Declare that your app needs camera permission by listing the permission android.permission.CAMERA in the AndroidManifest.xml file:

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

Since Android 6.0 (API level 23) you also have to implement a suitable permission requesting and handling at runtime. For more details please see the Android docs "Request App Permissions" as well as our basic example implementation.

Add Barcode Scanner Feature as a Dependency#

ScanbotBarcodeDetector is available with the SDK Package 1. You have to add the following dependencies for it:

api "io.scanbot:sdk-package-1:$latestSdkVersion"api "io.scanbot:sdk-barcode-assets:$latestSdkVersion"

Initialize the SDK#

The Scanbot Scanner SDK must be initialized before use. Add the following code snippets to your Application class:

import io.scanbot.sdk.ScanbotSDKInitializer
class ExampleApplication : Application() {
    override fun onCreate() {        super.onCreate()
        // Initialize the Scanbot Scanner SDK:        ScanbotSDKInitializer().initialize(this)    }}

ScanbotSDKInitializer#prepareBarcodeScannerBlobs(true) is deprecated and removed from the API. All Barcode Scanner assets will be prepared automatically if the appropriate assets dependency is added.

Ready To Use UI Components#

The Ready-To-Use UI (RTU UI) is a set of easy to integrate and customize high-level UI components (Activities) for the most common tasks in Scanbot Scanner SDK:

  • Barcode and QR-Code Scanner - BarcodeScannerActivity

The design and behavior of these ready-to-use Activities are based on our many years of experience as well as the feedback from our SDK customers.

Customization of RTU UI#

  • UI: All colors and text resources (localization).
  • Behavior: Enable or disable features like Flashlight, Barcode Filter, Image Snapping.

Please note: The main idea of the RTU UI is to provide simple-to-integrate and simple-to-customize Activity components. Due to this idea there are some limitations with the possibilities of customization. If you need more customization options you have to implement custom Activities using our "Classical SDK UI Components".

Start RTU UI Activity#

// Create the configuration (customization):val barcodeCameraConfiguration = BarcodeScannerConfiguration()barcodeCameraConfiguration.setFlashEnabled(true)barcodeCameraConfiguration.setCancelButtonTitle("Cancel")barcodeCameraConfiguration.setFinderLineColor(Color.GREEN)barcodeCameraConfiguration.setBarcodeFormatsFilter(...)// set further config properties ...
// Create an Intent for the BarcodeScannerActivity with the configuration and start it:val intent = BarcodeScannerActivity.newIntent(this@MainActivity, barcodeCameraConfiguration)startActivityForResult(intent, MY_BARCODE_UI_REQUEST_CODE)

Receive Activity Result#

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {    ...    if (requestCode == MY_BARCODE_UI_REQUEST_CODE && resultCode == Activity.RESULT_OK) {        val barcodeScanningResult = data?.getParcelableExtra<BarcodeScanningResult>(BarcodeScannerActivity.SCANNED_BARCODE_EXTRA)        // handle the result:        barcodeScanningResult.barcodeItems ...    }}

Additional RTU barcode scanning parameters#

Please see chapter Additional configuration below to see some additional parameters description.

Full Example of the RTU UI Activity usage#

Please see this full example implementation in our demo:

πŸ‘‰ MainActivity.kt

Classical SDK Components#

Our Classical SDK Components allows you to build your custom UI Activities which are very flexible and fully customizable. It is a set of easy to integrate and customize Views, Handlers, Controllers, etc. which can be used in your Activities to implement the most common tasks in the Scanbot Scanner SDK.


  • UI: Fully customizable
  • Behavior: Fully customizable

Integration of Classical SDK Components#

Use the classes ScanbotCameraView, BarcodeDetectorFrameHandler, ScanbotBarcodeDetector, BarcodeScannerConfig and BarcodeAutoSnappingController to build a custom scanner UI for Barcode and QR-Code scanning.

Example of a Custom Activity#

As a final step, you have to connect the ScanbotCameraView with BarcodeDetectorFrameHandler and BarcodeAutoSnappingController. The ScanbotBarcodeDetector can be used to detect and parse barcodes from still images (Bitmap), e.g. JPG files from the photo library or other sources. Add result handler for BarcodeDetectorFrameHandler:

barcodeDetectorFrameHandler.addResultHandler(object : BarcodeDetectorFrameHandler.ResultHandler {
    override fun handle(result: FrameHandlerResult<BarcodeScanningResult?, SdkLicenseError>): Boolean {        when (result) {            is FrameHandlerResult.Success -> {                val detectedBarcodes = result.value                // do something with result here            }            is FrameHandlerResult.Failure -> {                // handle license error here            }        }
        return false    }})

Please see this full example implementation of a fully customizable Activity in our demo:

πŸ‘‰ MainActivity.kt

Additional configuration#

Some peculiar use-cases require special handling. For example, we can configure ScanbotBarcodeDetector to scan only barcodes of expected lengths. This might reduce false scans. Such parameters work only for enumerated types of barcodes and, usually, you don't need to modify their default values.

You can specify these parameters via BarcodeScannerAdditionalConfig entity as a part of BarcodeScannerConfig:

val barcodeDetector = ScanbotSDK(this).createBarcodeDetector()val additionalConfig = BarcodeScannerAdditionalConfig(    minimumTextLength = 0,    maximumTextLength = 0,    minimum1DQuietZoneSize = 10,    gs1DecodingEnabled = true,)val config = BarcodeScannerConfig(    additionalConfig = additionalConfig,    // modify other parameters    )barcodeDetector.setConfig(config)

Alternatively, you can utilize methods modifyConfig and modifyAdditionalConfig to only edit some of parameters:

barcodeDetector.modifyConfig {    modifyAdditionalConfig {        setMinimumTextLength(0)        setMaximumTextLength(0)        setMinimum1DQuietZoneSize(10)        setGs1DecodingEnabled(true)        setStripCheckDigits(false)    }    // modify other parameters}

Parameters, currently available in BarcodeScannerAdditionalConfig are:

  • minimumTextLength: minimum required text length of the detected barcode. The default value is 0 (the setting is turned off). Currently works for ITF barcodes only!
  • maximumTextLength: maximum text length of the detected barcode. Setting to zero removes the limit. The default value is 0 (the setting is turned off). Currently works for ITF barcodes only!
  • minimum1DQuietZoneSize: minimum required quiet zone on the barcode. Measured in modules (the size of a minimal bar on the barcode). The default value is 10. Currently works for ITF barcodes only!
  • gs1DecodingEnabled: when set to true, the scanner assumes that the barcode can be a GS1 barcode. Turn it off, if you don't want to see decoded FNC1 characters ("]C1" and ASCII char 29). The default is true. Currently works for CODE128 barcodes only!
  • stripCheckDigits: when set to true, check digits for UPC, EAN and MSI Plessey codes are removed from result. Has no effect if both single and double digit MSI Plessey checksums are enabled. The default is false