How to enable Gallery Scan on Android

The SDK allows you to decode barcodes from image files. It supports several image formats, including BMP, PNG, and JPG. 

Here is an example of how you can access the photo library on your device and select and scan images from within the library

                private fun scanFromGallery() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        when {
            ActivityCompat.checkSelfPermission(
                this,
                storagePermission
            ) == PackageManager.PERMISSION_GRANTED -> {
                startImagePicker()
            }

            shouldShowRequestPermissionRationale(storagePermission) -> {
                showStorageRequestPermissionRationale()
            }

            else -> {
                storagePermissionResult.launch(storagePermission)
            }
        }
    } else
        startImagePicker()
}

private fun startImagePicker() {
    val pickImageIntent = Intent(Intent.ACTION_PICK)
    pickImageIntent.type = "image/*"
    pickImageResult.launch(pickImageIntent)
}

private fun scanImageFromUri(uri: Uri?) {
    binding.progressIndicator.isVisible = true
    ImageUtil.bitmapFromUri(contentResolver, uri,3000,3000)?.let {
        BarkoderHelper.scanImage(
            it,
            BKDConfigUtil.configureBKD(
                this,
                ScanMode.GALLERY_SCAN,
                true
            ),
            this, this
        )

    }
}
            

History:

close