Skip to main content

SDK initialization

The Scanbot Barcode Scanner SDK must be initialized before usage. Ensure the initialization is called as early as possible in your Compose Multiplatform application.

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.

To initialize the SDK, add the following code snippet:

import io.scanbot.sdk.compose.multiplatform.common.*
import io.scanbot.sdk.compose.multiplatform.sdk.*

var config = ScanbotSdkConfig(
licenseKey = "<YOUR_SCANBOT_SDK_LICENSE_KEY>",
loggingEnabled = true,
);

ScanbotSDK.initialize(config);

The following configuration options can be passed on initialization:

  • licenseKey: Your license key for the Scanbot SDK.
  • imageQuality: Optional image quality value. Defines the quality factor of JPEG images. The value must be between 1 and 100, where 100 means maximum quality and largest file size. The default value is 80, which is a good compromise between image file size and document legibility.
  • imageFormat: Optional image format in which all pages will be stored.
  • loggingEnabled: Optional logging flag. While it may be useful for development, consider switching logging OFF in production builds for security and performance reasons!
  • documentDetectorMode - Optional mode for document detection.
    • 'ML_BASED' is the default mode, based on Machine Learning-based approach;
    • 'EDGE_BASED' legacy mode, based on classic Computer Vision algorithms.
  • useCameraX: Optional flag to disable the usage of CameraX Android APIs for Ready to Use UI components (Android only). Default is true.
  • allowGpuAcceleration: Optional flag to enable GPU acceleration for TensorFlow ML models (Android only). Default is true. If set to false, GPU acceleration will be disabled for Barcode Scanner.
  • allowXnnpackAcceleration: Optional flag that controls whether XNN pack optimizations should be used (Android only). Default is true.

Add Scanbot SDK license key

info

You can use the Scanbot Barcode SDK for quick testing or evaluation purposes even without a license key. However, the SDK will only work for 60 seconds per app session and may not be used for production purposes. Want to scan longer than 60 seconds? Get your free trial license key here.

Example code for initialization with license:

import io.scanbot.sdk.compose.multiplatform.common.*
import io.scanbot.sdk.compose.multiplatform.sdk.*

// Separate configuration constants
private const val LICENSE_KEY = "fXbN2PmyqEAZ+btdkSIS36TuX2j/EE5qxVNcZMXYErbLQ" +
"3OBnE10aOQxYI8L4UKwHiZ63jthvoFwUevttctBk0wVJ7Z" +
"+Psz3/Ry8w7pXvfpB1o+JrnzGGcfwBnRi/5raQ2THDeokR" +
"RB1keky2VBOFYbCfYt3Hqms5txF2z70PE/SBTMTIVuxL7q" +
"1xcHDHclbEBriDtrHw8Pmhh9FqTg/r/4kRN/oEX37QGp+Y" +
"3ogwIBbSmV+Cv+VuwtI31uXY3/GkyN/pSJZspIl+exwQDv" +
"O0O1/R/oAURpfM4ydaWReRJtjW8+b1r9rUgPERguaXfcse" +
"HlnclItgDfBHzUUFJJU/g==\nU2NhbmJvdFNESwppby5zY" +
"2FuYm90LmRlbW8ueGFtYXJpbgoxNDg0NjExMTk5CjcxNjc" +
"KMw==\n"

// Function to configure Scanbot SDK
private fun configureScanbotSdk(): ScanbotSdkConfig {
return ScanbotSdkConfig(
licenseKey = LICENSE_KEY,
loggingEnabled = true,
)
}

// Main Composable function
@Composable
fun App() {
val scanbotSdkConfig = remember { configureScanbotSdk() }
ScanbotSDK.initialize(scanbotSdkConfig)

// UI components and other logic go here
}

You will be unable to use any of the SDK features if the license key is corrupted, expired, or invalid in any other way.

Please make sure that you have inserted the exact key as it was provided by us, including all encoded line breaks \n.

App identifier

Every app has a unique identifier (sometimes also known as "bundle identifier" or "application ID"). Your license will be bound to this identifier. To request a trial license or purchase a production license you have to provide us the bundle identifier of your app.

For Android: Please see the applicationId in the app-level build.gradle file of your android project:

defaultConfig {
...
applicationId "io.scanbot.barcode.example.app.compose"
}

For iOS: In Xcode see the Bundle Identifier in the "General" settings tab of your project.

License handling

caution

If your Scanbot SDK license has expired, any call to the Scanbot SDK API will return empty results. To prevent this you should always check for license expiration during the runtime via ScanbotSDK.getLicenseStatus(). If the result of await returns result.isLicenseValid == false, you should disable any usage of the Scanbot SDK (functions, UI components, etc).

See license handling section to learn how to handle the different license statuses in your app.

Logging

When initializing the Scanbot Barcode Scanner SDK you can enable logging of the SDK. By default logging is disabled.

import io.scanbot.sdk.compose.multiplatform.common.*
import io.scanbot.sdk.compose.multiplatform.sdk.*

var config = ScanbotSdkConfig(
loggingEnabled = true,
// ...
);
ScanbotSDK.initialize(config);

On Android logs are printed into LogCat as well as saved on the device. The easiest way to check the log outputs on Android is to use Android Debug Bridge (adb). (e.g. $ adb -s <DEVICE_ID> shell "logcat")

On iOS all logs are printed to the console. Please use Xcode to check the log outputs. There will be no log files created by the Scanbot Barcode Scanner SDK plugin.

Please note: While it may be useful for development, consider switching logging OFF in production builds for security and performance reasons!

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?