MRZ Scanner Guide
for
Android

SDK v.1.9.1

Installation guide

Please follow these simple steps to integrate our SDK into your Android project:

  1. Copy mrzscannerlib.aar in the libs/ folder
  2. Add the following dependencies in your app’s build.gradle file:


  1. Add this code in the root of you app’s build.gradle file to link the libs/ dir:

flatDir {

                dirs 'libs'

        }

}

  1. Add the following code to the layout.xml of the activity where you want the scanner to be shown:
       (Partial scanning view is also possible by positioning and resizing the scanner fragment)

android:id="@+id/scannerFragment"

android:name="com.scansolutions.mrzscannerlib.MRZScanner"

android:layout_width="match_parent"

android:layout_height="match_parent" />

  1. Use this code to configure the scanner. The code should be added in the activity where the scanning will take place.

MRZScanner mrzScanner = (MRZScanner) getSupportFragmentManager().findFragmentById(R.id.scannerFragment);

mrzScanner.setScannerType(ScannerType.SCANNER_TYPE_MRZ); // Options: [SCANNER_TYPE_MRZ, SCANNER_TYPE_DOC_IMAGE_ID, SCANNER_TYPE_DOC_IMAGE_PASSPORT, TYPE_DRIVING_LICENCE]

MRZScanner.setIDActive(true);          // Enable/disable the ID document type

MRZScanner.setPassportActive(true);    // Enable/disable the Passport document type

MRZScanner.setVisaActive(true);        // Enable/disable the Visa document type

MRZScanner.setMaxThreads(2);           // Set the max CPU threads that the scanner can use

MRZScanner.registerWithLicenseKey(this, "licence_key", new MRZLicenceResultListener() {

   @Override

   public void onRegisterWithLicenceResult(int result, @Nullable String errorMessage) {

       if (errorMessage != null) {

           Log.i(TAG, "Result code: " + result + ". " + errorMessage);

       } else {

           Log.i(TAG, "Result code: " + result + ". Registration successful.");

       }

   }

});

String sdkVersion = MRZScanner.sdkVersion(); // Get the current SDK version of MRZScanner

  1. Implement the MRZScannerListener interface as a listener for a successful MRZ scan:

public class MainActivity extends AppCompatActivity implements MRZScannerListener { ...

class MainActivity : AppCompatActivity(), MRZScannerListener { ...

API description

/**

* Set the scanning rectangle to limit the scanning area. The parameters' values are representing percentages of the scanning preview.

*

* @param x      the top left point of the scanning rectangle. [0,...,100] Default value: 5.

* @param y      the top left point of the scanning rectangle. [0,...,100] Default value: 20.

* @param width  width the width of the scanning rectangle. [0,...,100] Default value: 90.

* @param height height the height of the scanning rectangle. [0,...,100] Default value: 60.

*/

public void setScanningRectangle(int x, int y, int width, int height)

/**

* Specify whether the scanner should detect and return result for IDs.

*

* @param isIDActive [true, false]. The default value is true.

*/

public static void setIDActive(boolean isIDActive)

/**

* Specify whether the scanner should detect and return result for passports.

*

* @param isPassportActive [true, false]. The default value is true.

*/

public static void setPassportActive(boolean isPassportActive)

/**

* Specify whether the scanner should detect and return result for visas.

*

* @param isVisaActive [true, false]. Default value is true.

*/

public static void setVisaActive(boolean isVisaActive)

/**

* Specify the maximum number of CPU threads that the scanner can use during the scanning process.

*

* @param maxThreads number of CPU threads. Default value is 2.

*/

public static void setMaxThreads(int maxThreads)

/**

* Specify which scanner type you want to use. There are two options: "MRZ Scanner" and "Document Image scanner".

* The "MRZ Scanner" option is used to scan for MRZ.

* The "Document image scanner" is used for capturing front and back image of the ID documents.

*

* @param scannerType [SCANNER_TYPE_MRZ, SCANNER_TYPE_DOC_IMAGE_ID, SCANNER_TYPE_DOC_IMAGE_PASSPORT]. Default value is SCANNER_TYPE_MRZ

*/

public void setScannerType(ScannerType scannerType)

/**

* Resume scanning after the scanner has been paused/stopped. Usually after a successful scan.

*/

public static void resumeScanning()

/**

* Register with the licence key provided to remove the asterisks (*) from the result.

*

* @param context                   the activity's context.

* @param key                       the provided licence key.

* @param mrzLicenceResultListener  register result callback where int @result is 0 when registration is successful <0 when registration failed.

*                                  @errorMessage is null when registration is successful, otherwise @errorMessage is an error description String.

*/

public static void registerWithLicenseKey(final Context context, final String key, @Nullable final MRZLicenceResultListener mrzLicenceResultListener)

/**

* Register with the licence key provided to remove the asterisks (*) from the result.

*

* @param context the activity's context.

* @param key     the provided licence key.

* @return 0 for success, <0 if registration failed.

*

* @deprecated use {@link MRZScanner#registerWithLicenseKey(Context, String, MRZLicenceResultListener)} instead.

*/

@Deprecated

public static int registerWithLicenseKey(final Context context, final String key)

/**

* Scan for a single bitmap.

*

* @param bitmap   the image to be scanned.

* @param activity the initialisation activity context.

*/

public static void scanBitmap(final Bitmap bitmap, final Activity activity, final MRZScannerListener listener)

/**

* Trigger an image picker.

*

* @param activity the initialisation activity context.

*/

public static void scanFromGallery(final Activity activity, final MRZScannerListener listener)

/**

* Show a warning alert dialog if the camera's resolution is lower than 5 MP and if the camera lacks the AutoFocus feature.

*

* @param shouldWarn [true, false]. Default value is true.

*/

public static void warnIncompatibleCamera(boolean shouldWarn)

/**

* Set valid issuing country codes. Successful scans with country codes not included in the array will be ignored.

*

* @param validIssuingCountries array with active country codes. Example value: new String[]{"foo", "bar"}.

*/

public static void setValidIssuingCountries(String[] validIssuingCountries)

/**

* Set custom overlay image for the scanner.

*

* @param customImage bitmap representation of the overlay image

*/

public void setCustomImageOverlay(Bitmap customImage)

/**

* Set custom overlay image for the scanner.

*

* @param customImageResId resource id of the overlay image

*/

public void setCustomImageOverlay(int customImageResId)

/**

* Enable scan from gallery. If enabled, a "scan from gallery" button will appear in the scanner preview.

*

* @param enabled indicates whether the "scan from gallery"  is enabled. Default value: false.

*/

public void enableScanFromGallery(boolean enabled)

/**

* Enable upside-down scanning. If enabled, the scanner will also try the upside-down format of the preview.

*

* @param enabled indicates whether the "upside-down" feature  is enabled. Default value: false.

*/

public static void setEnableUpsideDownScanning(boolean enabled)

/**

* Set valid nationality and issuing country codes. Successful scans with country codes not included in the array will be ignored.

*

* @param validCountryCodes array with active country codes. Example value: new String[]{"GBR", "USA"}. Default: {} (ALL).

*/

public static void setValidCountryCodes(String[] validCountryCodes)

/**

* Specify whether validation of country codes is enabled.

*

* @param enabled indicates whether validation is enabled. Default: true.

*/

public static void setValidateCountryCodesEnabled(Boolean enabled)

/**

* Turn flash on or off.

*

* @param on true = on, false = off. Default value: false.

*/

public void toggleFlash(Boolean on)

/**

* Enable vibration on successful scan.

*

* @param enabled indicates whether the vibration feature  is enabled. Default value: true.

*/

public static void setEnableVibrationOnSuccess(boolean enabled)

/**

* Continuous scanning. If enabled, after successful scan, the scanner view will not be paused.

*

* @param enabled indicates whether the scanner should stay active after a successful scan. Default value: false.

*/

public void setContinuousScanningEnabled(boolean enabled)

/**

* Ignore duplicates when scanning continuously.

*

* @param ignore indicates whether the scanner should repeat the last successful scan. Default value: true.

*/

public void setIgnoreDuplicates(boolean ignore)

CHANGELOG

- v1.9.1

- v1.9.0

- v1.8.2

- v1.8

-v1.7.1

-v1.7

 

- v1.6

- v1.5:

If you have any questions or concerns please visit our site at www.mrzscanner.com where you can register and send us a support request ticket at our Developer Portal, or feel free to contact us at contact@mrzscanner.com.