Skip to main content

SDK Initialization | Android Barcode Scanner

License Key

In order to run the Scanbot SDK within your production app, you must purchase and use a valid Scanbot SDK license.

Each license key is valid only for a given app bundle identifier. You will be unable to use any of the SDK features if the license key is corrupted, expired, or invalid in any other way.

Getting a Trial License

The Scanbot SDK will run without a license for one minute per session! To get a free, "no-strings-attached" 7-day trial license, please submit the Trial License Form on our website.

Please kindly note that a trial license can only be used in a development and staging environment. You are not allowed to publish your app to the App Store, Play Store, or any 3rd party Android App Store with a trial license.

Purchase a Production License

To get pricing information and purchase a production license for the Scanbot SDK please request a quote.

Initialize

Free Developer Support

We provide free "no-strings-attached" developer support for the implementation & testing of the Scanbot SDK. If you encounter technical issues with integrating the Scanbot SDK or need advice on choosing the appropriate framework or features, please visit our Support Page.

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

import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDKInitializer

class ExampleApplication : Application() {

override fun onCreate() {
super.onCreate()

// Initialize the Scanbot Barcode Scanner SDK:
ScanbotBarcodeScannerSDKInitializer().initialize(this)
}
}

Don't forget to register the application class in AndroidManifest.xml:

<application
...
android:name=".ExampleApplication"
...

Use the method license(application, "YOUR_SCANBOT_BARCODE_SCANNER_SDK_LICENSE_KEY") on initialization of the Scanbot Barcode Scanner SDK to set your license key:

// This is an expired license key. Used only for demo code purposes!
val LICENSE_KEY =
"MiKudIf/IFGnwk/0ZQAhx58IGEV8/L" +
"d6dF/F/j2TyLNNb+TCaIsQLOf2+/Ih" +
"LRRPvRsHESA/b0KFqnxYl4briv3kzQ" +
"tSTrvDJ9mE15rxU/Pob4XRnjTSc9B7" +
"P/CpM0HDkmM02U8ljt0kKwpQSRZkiz" +
"rBe+qttmA0b00ZEcyfn9t2xP4zRdaD" +
"ayjWAdZi82oP3UST3bLIV8I90Qordf" +
"s+u23JKL52bQY+HB1HNW7Ow8rA4+Mg" +
"Lr/wE2N+UBElHPOZLtQBTHYUvbVwVU" +
"KZDWOEv8VfrTmn2XA0tKVSDaxL6z7B" +
"1s2g83XWYaxXrf4A3q/fkSNvDN1oic" +
"Dvs0gbD1Lf0w==\nU2NhbmJvdFNESw" +
"ppby5zY2FuYm90LmV4YW1wbGUuc2Rr" +
"LmFuZHJvaWQKMTQ3ODA0NDc5OQoyCj" +
"I=\n";

ScanbotBarcodeScannerSDKInitializer()
.withLogging(true)
.license(this, LICENSE_KEY)
.initialize(this)

Please make sure that you have inserted the exact key as it is stated in the license file - with all encoded line breaks \n.

License Checks in Production Apps

caution

If your Scanbot Barcode Scanner SDK license has expired, calls to the Scanbot Barcode Scanner SDK API will return empty results. To prevent this you should always check for license expiration during the runtime via licenseInfo.isValid. If this property returns false, you should disable any usage of the Scanbot Barcode Scanner SDK (functions, UI components, etc).

To handle License errors properly the IScanbotSDKLicenseErrorHandler can be used. The callback will be triggered if any license error has occurred. Use the following snippet to initialize the Scanbot Barcode SDK with a callback.

ScanbotBarcodeScannerSDKInitializer()
.withLogging(true)
.license(this, LICENSE_KEY)
.licenceErrorHandler(IScanbotSDKLicenseErrorHandler { status, feature, message ->
// Handle license errors here:
LoggerProvider.logger.d("ScanbotBarcodeScannerSDK", "license status:${status.name}, message: $message")
if (feature != SdkFeature.NoSdkFeature) {
LoggerProvider.logger.d("ExampleApplication", "Missing SDK feature in license: ${feature.name}")
}
})
.initialize(this)
info

We highly recommend implementing a suitable handling of this case in your app!

Example code for checking the license status:

import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDK

// Check the license status:
val licenseInfo = ScanbotBarcodeScannerSDK(activity).licenseInfo
LoggerProvider.logger.d("ExampleApplication", "License status: ${licenseInfo.status}")
LoggerProvider.logger.d("ExampleApplication", "License isValid: ${licenseInfo.isValid}")
LoggerProvider.logger.d("ExampleApplication", "License message: ${licenseInfo.licenseStatusMessage}")

if (licenseInfo.isValid) {
// Making your call into ScanbotBarcodeScannerSDK API is now safe.
// e.g. start barcode scanner
}

Control detection acceleration and optimizations

There are a few options developers can use to manage the SDK's detection performance.

  • Xnnpack acceleration - setting Xnnpack acceleration for ML models provides highly-optimized implementations of floating-point neural network operators and can improve performance up to 4x. It is enabled by default and only disabled for models that have shown problems during testing. If you encounter any problems with the detection you could try to disable this option by setting:
ScanbotBarcodeScannerSDKInitializer()
.allowXnnpackAcceleration(false)
...
.initialize(this)
  • GpuAcceleration - allows accelerating ML models using the GPU of the mobile device. By default it is enabled. To disable it set:
ScanbotBarcodeScannerSDKInitializer()
.allowGpuAcceleration(false)
...
.initialize(this)
caution

Unfortunately, we have noticed that all devices using a Cortex A53 processor DO NOT SUPPORT GPU acceleration. If you encounter any problems, please disable GPU acceleration for these devices.

ScanbotBarcodeScannerSDKInitializer()
.allowGpuAcceleration(false)
  • Precompilation of the GPU ML models - allows to precompile ML model data thus speeding up the second and subsequent scanner initializations, but as a downfall the initial start of the scanner will be quite slow. It is disabled by default but can be enabled by setting:
ScanbotBarcodeScannerSDKInitializer()
.precompileGpuMlModels(precompilingCallback)
...
.initialize(this)

Where:

  • precompilingCallback is a lambda that will be triggered when GPU ML models compilation has completed.

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?