Customizing the MRZ Scanner
When developing with MRZScannerActivity, you can add configurations via the MRZScannerConfig class. This page will guide you on how to configure the settings.
MRZScannerConfig Overview
The MRZScannerConfig class is capable of configuring almost all customization options applicable to MRZ scanning use cases with the MRZ Scanner. The MRZ Scanner uses passes an MRZScannerConfig object to the constructor when creating an MRZ Scanner instance. MRZScannerConfig contains the following properties:
-
setLicense/getLicense- the license key is the only property whose value must be specified when instantiating the MRZ Scanner instance. If the license is undefined, invalid, or expired, the MRZ Scanner cannot proceed with scanning, and instead displays a pop-up error message instructing the user to contact the app administrator to resolve this license issue. -
setDocumentType/getDocumentType- specifies the type of document that the MRZ Scanner will recognize. This property accepts values defined in the EnumDocumentType such asEnumDocumentType.All,EnumDocumentType.Id, orEnumDocumentType.Passport. It helps the scanner to optimize its processing based on the expected document type. To learn more about the different document types that are supported, please refer to the Supported Document Types section of the user guide. -
setTemplateFile/getTemplateFile- a template file is a JSON file or JSON string that contains a series of algorithm parameter settings (called Capture Vision templates) that is usually used for very specific and customized scanning and parsing scenarios. ThetemplateFilepoints to the location of the JSON file. The MRZ Scanner comes with a default template file, but you may choose to use a custom template to target specialized use cases. We recommend contacting the Dynamsoft Technical Support Team for assistance with template customization. -
setBeepEnabled/isBeepEnabled(default valuefalse) - a boolean that determines whether a beep sound is triggered upon a successful MRZ scan. When enabled (true), the scanner will play a sound to provide audible feedback. -
setCameraToggleButtonVisible/isCameraToggleButtonVisible(default valuefalse) - a boolean that specifies whether the camera toggle button is displayed. This button lets users switch between available cameras (e.g., front and rear). -
setCloseButtonVisible/isCloseButtonVisible(default valuetrue) - a boolean to control the visibility of the close button on the scanner’s UI. If true, a close button will be displayed allowing users to exit the MRZ scanning interface. -
setGuideFrameVisible/isGuideFrameVisible(default valuetrue) - serves as a toggle to show or hide the guide frame in the UI during scanning. The guide frame assists users in properly aligning the document for optimal MRZ detection. When set to true, a visual overlay is displayed on the scanning interface. -
setTorchButtonVisible/isTorchButtonVisible(default valuetrue) - determines whether the torch (flashlight) toggle button is visible on the scanning interface. Set to true to allow users to switch the device’s flashlight on or off during MRZ scanning. -
setVibrateEnabled/isVibrateEnabled(default valuefalse) - controls the scanner’s ability to make the scanning device vibrate upon a successful MRZ scan. When enabled (true), the scanner will vibrate to provide haptic feedback if the device supports it.
Next, we go over the different ways that these properties can be used to customize the scanner with a few examples.
Setting the MRZ Document Type
Using the API
Specifies the type of document to scan, such as ID cards or passports. It also improves the processing speed and the accuracy.
- Java
- Kotlin
MRZScannerConfig config = new MRZScannerConfig(); config.setDocumentType(EnumDocumentType.DT_PASSPORT);val config = MRZScannerConfig().apply { documentType = EnumDocumentType.DT_PASSPORT }
Using a customized template file
A template file is a JSON file that includes a series of algorithm parameter settings. It is always used to customize the performance for different usage scenarios. Contact us to get a customized template for your scanner.
-
Add a Templates folder to the assets folder of your project at src\main\assets\Templates. Put your JSON file in the Templates folder.
-
Specify the template file via setTemplateFile
- Java
- Kotlin
MRZScannerConfig config = new MRZScannerConfig(); config.setTemplateFile("CustomizedTemplate.json");val config = MRZScannerConfig().apply { templateFile = "CustomizedTemplate.json" }
You can also use a JSON string as the template file.
Related APIs
Configure the UI Elements

MRZ Scanner UI Component
- Close button: Stop MRZ scanning and go back to the previous activity.
- Torch button: A clickable button that can turn on/off the torch.
- Java
- Kotlin
MRZScannerConfig config = new MRZScannerConfig(); config.setTorchButtonVisible(false); config.setGuideFrameVisible(false); config.setCloseButtonVisible(false);val config = MRZScannerConfig().apply { torchButtonVisible = false guideFrameVisible = false closeButtonVisible = false }
Related APIs
Enabling Haptic and Audio Feedback
The MRZ Scanner library also offers the option to enable audio and haptic feedback upon a successful MRZ scan. Through the setBeepEnabled and setVibrateEnabled methods, you can choose to play a sound or make the device vibrate once the MRZ is recognized.
- Java
- Kotlin
MRZScannerConfig config = new MRZScannerConfig(); config.setBeepEnabled(true); config.setVibrateEnabled(true);val config = MRZScannerConfig().apply { isBeepEnabled = true isVibrateEnabled = true }
Related API
Further Customization
If you have other customization requirements on the MRZScanner component, you can modify it with the open source code on GitHub.