Android Installation
1. Add the package #
Way 1: the barkoder module (Groovy DSL) #
Download the Android SDK package from Downloads in the barKoder Developer Portal and unzip it. In Android Studio, choose File › New › Import Module and pick its barkoder folder: the one that holds both barkoder.aar and build.gradle, not the barkoder.aar file.
Add Dependency #
In your app's build.gradle, add the dependency:
implementation project(path: ':barkoder')
Way 2: the AAR file (Kotlin DSL) #
Or put the AAR file itself in your app (for projects with Kotlin DSL Gradle files):
Create a libs folder in your app directory #
Put barkoder.aar in libs folder #
Add to build.gradle.kts (Module :app): #
implementation(files("libs/barkoder.aar"))
2. Add the scanner view #
Add Activity/Fragment #
In the layout of the activity or fragment that shows the scanner, add the view:
<com.barkoder.BarkoderView
android:id="@+id/bkdView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
3. Set the license key and barcode types #
Licensing #
(Unlicensed) and part of its data is replaced with dots. Get a free trial key on the trial page: choose Native or WASM and enter your app ID (for the Web SDK, your domain). A trial key lasts 30 days, for up to 25 devices, one per app ID. For a production license, request a quote. By using the SDK you agree to the End User License Agreement.Create Barkoder Config #
In your activity, set the config with your license key. The template sets the other settings for one kind of use, here industrial 1D barcodes:
bkdView.config = BarkoderConfig(this, "LICENSE_KEY") {
Log.i("LicenseInfo", it.message)
}
BarkoderHelper.applyConfigSettingsFromTemplate(
this,
bkdView.config,
BarkoderConfigTemplate.INDUSTRIAL_1D,
null
)
Enabling Symbologies #
Turn on the barcode types you scan, all at once or one by one:
private fun setActiveBarcodeTypes() {
// There is option to set multiple active barcodes at once as array
bkdView.config.decoderConfig.SetEnabledDecoders(
arrayOf(
Barkoder.DecoderType.QR,
Barkoder.DecoderType.Ean13,
Barkoder.DecoderType.IDDocument // enable mrz
)
)
// or configure them one by one
bkdView.config.decoderConfig.UpcA.enabled = true
}
4. Start scanning and read results #
Add BarkoderResultCallback #
Each result comes to scanningFinished. Add BarkoderResultCallback to your activity:
class MainActivity : AppCompatActivity(), BarkoderResultCallback {
....
override fun scanningFinished(results: Array<Barkoder.Result>, thumbnails: Array<Bitmap>?, imageResult: Bitmap?) {
Log.i("Scanned result", results.firstOrNull()?.textualData ?: "nothing read")
}
}
Start Scanning #
Finally, start scanning, for example from a Scan button. The first time, the SDK asks the user for the camera permission (it is already in the SDK's manifest):
bkdView.startScanning(this)