Skip to main content

SDK Initialization | Android Barcode Scanner

License Key#

In order to run the Scanbot SDK functionality within your production app, you have to 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.

Trial License#

The Scanbot SDK will run without a license for one minute per session! To get an unrestricted, "no-strings-attached" 30-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#

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)    }}

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 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.getLogger().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).licenseInfoLoggerProvider.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 safe now.    // e.g. start barcode scanner}