Android Gallery scan
The SDK allows you to decode barcodes from image files. It supports several image formats, including BMP, PNG, and JPG.
Here is how to scan a picture from the device's photo gallery (the SDK opens the gallery), or a picture you already have as a Bitmap. Put these in your activity that implements BarkoderResultCallback: the result comes to scanningFinished.
import android.graphics.Bitmap
import android.util.Log
import com.barkoder.BarkoderConfig
import com.barkoder.BarkoderHelper
import com.barkoder.enums.BarkoderConfigTemplate
// A config for pictures: your license key and the gallery scan template
private val galleryConfig: BarkoderConfig by lazy {
BarkoderConfig(this, "LICENSE_KEY") { Log.i("LicenseInfo", it.message) }.also {
BarkoderHelper.applyConfigSettingsFromTemplate(this, it, BarkoderConfigTemplate.GALLERY_SCAN, null)
// the template turns on ID Document (MRZ): keep it on only if your license includes it, otherwise every
// picture comes back as "ID Document decoder type is not licensed!"
it.decoderConfig.IDDocument.enabled = false
}
}
// Opens the device's photo gallery and scans the picture the user chooses
private fun scanFromGallery() {
BarkoderHelper.scanFromGallery(this, galleryConfig, this, this)
}
// Scans a picture you already have
private fun scanBitmap(bitmap: Bitmap) {
BarkoderHelper.scanImage(bitmap, galleryConfig, this, this)
}