Skip to main content

Scanning an European health insurance card from an image | Android Document Scanner

The EHIC Scanner in the Scanbot SDK is capable of not only performing live detection of EHIC (European Health Insurance Cards) data but also extracting content from still images that have been imported from the gallery or any other source.


The Example Apps are available to see the EHIC scanner in action and to gain a comprehensive understanding of how to integrate it into your project:

Feature Dependency

The HealthInsuranceCardScanner feature is available with SDK Package 3. The following dependencies need to be added:


SDK Initialization

Before use, the Scanbot SDK needs to be initialized. The following code snippet should be added to your Application class:

import io.scanbot.sdk.ScanbotSDKInitializer

class ExampleApplication : Application() {

override fun onCreate() {

// The Scanbot Scanner SDK initialization:
.license(this, licenseKey)
// TODO: other configuration calls

The ScanbotSDKInitializer#prepareBarcodeScannerBlobs(true) function is deprecated and has been removed from the API. All Barcode Scanner assets will be prepared automatically if the appropriate assets dependency is added.

Image Processing

To select an image from the photo library and run detection on it, a class for an image import contract is created using the modern Android result API.

class ImportImageContract(private val context: Context) : ActivityResultContract<Unit, Bitmap?>() {
override fun createIntent(context: Context, input: Unit): Intent {
// An image is selected from the photo library and document detection is run on it:
val imageIntent = Intent()
imageIntent.type = "image/*"
imageIntent.action = Intent.ACTION_GET_CONTENT
imageIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, false)
imageIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)

return Intent.createChooser(imageIntent, "Select a picture")

private fun processGalleryResult(data: Intent): Bitmap? {
val imageUri =
return MediaStore.Images.Media.getBitmap(context.contentResolver, imageUri)

override fun parseResult(resultCode: Int, intent: Intent?): Bitmap? {
return if (resultCode == Activity.RESULT_OK && intent != null) {
return processGalleryResult(intent)
} else {

To run the gallery call and get a Bitmap using ImportImageContract, the following code is used:

 val galleryImageLauncher =
registerForActivityResult(ImportImageContract(this)) { resultEntity ->
lifecycleScope.launch(Dispatchers.Default) {
val activity = this@MainActivity
val sdk = ScanbotSDK(activity)
if (!sdk.licenseInfo.isValid) {
withContext(Dispatchers.Main) {
"License has expired!",
} else {
resultEntity?.let { bitmap ->
// Image processing is carried out
// processImage()
findViewById<View>( {

Scanner Creation

    val scanbotSDK = ScanbotSDK(this)
val healthInsuranceCardScanner = scanbotSDK.createHealthInsuranceCardScanner()

A new HealthInsuranceCardScanner is created each time createHealthInsuranceCardScanner() is called, and memory is initialized for it. If more than one import operation is expected, do not create new scanners for each operation.


The Scanbot SDK is used to detect the desired element on the imported bitmap.

    private fun processImage(
healthInsuranceCardScanner: HealthInsuranceCardScanner,
bitmap: Bitmap
) {
val result = healthInsuranceCardScanner.recognizeBitmap(bitmap, 0)
if (result != null && result.status == HealthInsuranceCardDetectionStatus.SUCCESS) {
// EHIC recognition results are processed
// processResult(result)

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?