Upgrade Guide to Anyline 4

The 4 Anyline SDK introduced new structure concept. The SDK is now composed from ScanView, ScanViewPlugins and ScanPlugins, being more structured and easy to implement. The components (ScanView, ScanViewPlugin and ScanPluign) are described in: Android Plugins.

This document will guide you through the necessary steps to upgrade your app to work with the Anyline SDK 4.

Prerequisites: Implement the new SDK

To add update the version of the Anylyine SDK, change the version number to the new version and add it to your app gradle as described in the Android Quick Start Guide.

After the gradle sync is completed, your project is going to show some errors in your ResultListener implementations. The following sections describe the required changes in order to adapt to the new interfaces.

Old Implementation vs. New Implementation

In the older versions of Anyline, the ScanModule was handling every part of the Anyline SDK. The View Elements are now separated from the use case code.
For the old implementation, first step was to take the mrzScanView which was of MrzScanView in Java. Afterwards, the configuration for the camera, flash button, cutout and visual feedback were loaded via JSON file. The last step was to initialize the module with the license key and the Result listener. The below code describes the module MRZ before Anyline 4.

Old Implementation for MRZ
    mrzScanView = (MrzScanView) findViewById(R.id.mrz_view);

    // add a camera open listener that will be called when the camera is opened or an error occurred
    //  this is optional (if not set a RuntimeException will be thrown if an error occurs)
    mrzScanView.setCameraOpenListener(this);
    // the view can be configured via a json file in the assets, and this config is set here
    // (alternatively it can be configured via xml, see the Energy Example for that)
    mrzScanView.setConfigFromAsset("mrz_view_config.json");

    // initialize Anyline with the license key and a Listener that is called if a result is found
    mrzScanView.initAnyline(getString(R.string.anyline_license_key), new MrzResultListener() {

        @Override
        public void onResult(MrzResult mrzResult) {
            // This is called when a result is found.
            // The Identification includes all the data read from the MRZ
            // as scanned and the given image shows the scanned ID/Passport

            Identification identification = mrzResult.getResult();
            identification.toJSONObject();

            //set the path of the mrz Image
            String path = setupImagePath(mrzResult.getCutoutImage());



            startScanResultIntent(getResources().getString(R.string.title_mrz), getIdentificationResult(identification), path);
            setupScanProcessView(ScanMrzActivity.this, mrzResult, getScanModule());
        }
    });

    mrzScanView.setDebugListener(this);

Starting with Anyline 4 each use case needs three components to successfully scan:

  • A ScanPlugin
    • The ScanPlugin handles the image processing and the scanning functionality itself.
    • Everything regarding scanning will be handled by the ScanPlugin.
    • In Android the ScanPlugin is initialisez internally (in the SDK) once the ScanViewPlugin is initialised.
  • A ScanViewPlugin
    • The ScanViewPlugin handles the UI and the ScanFeedback, which will be presented to the user.
    • Everything regarding UI configuration will be handled by the ScanViewPlugin.
    • A ScanViewPlugin has to be instantiated with a ScanPlugin and optionally with a UI Config.
  • A ScanView
    • The ScanView will handle the camera, the flash and manages the previously created ScanViewPlugin and ScanPlugin.
    • The ScanView will be initialised with a ScanView object in Java.


In the new implementation, as a fist step you have to take the scanView which is now a generic type for all ScanPlugins. The next step is to instantiate the ScanViewPluginConfig which hold on the configuration for cutout and scan feedback. The ScanViewPlugin should be afterwards instantiated with the license key. Internally it will instantiate the ScanPlugin of the same type which will be responsable for start and stop scanning. The last step is to set the scanViewPlugin to the ScanView and add the scanResultListener.

New Implementation for MRZ
    mrzScanView = (MrzScanView) findViewById(R.id.scan_view);

    // add a camera open listener that will be called when the camera is opened or an error occurred
    //  this is optional (if not set a RuntimeException will be thrown if an error occurs)
    mrzScanView.setCameraOpenListener(this);
    //add the mrzConfig specific for MRZ
    MrzConfig mrzConfig = new MrzConfig();
    mrzConfig.setStrictMode(false);

    //init the scanViewPlugin configuration which hold the scan view ui configuration (cutoutConfig and ScanFeedbackConfig)
    ScanViewPluginConfig mrzScanViewPluginConfig = new ScanViewPluginConfig(getApplicationContext(), "mrz_view_config.json");
    //init the scan view
    IdScanViewPlugin scanViewPlugin = new IdScanViewPlugin(getApplicationContext(), getString(R.string.anyline_license_key), mrzScanViewPluginConfig, mrzConfig);
    //init the base scanViewconfig which hold camera and flash configuration
    BaseScanViewConfig scanViewBaseConfig = new BaseScanViewConfig(getApplicationContext(), "mrz_view_config.json");
    //set the base scanViewConfig to the ScanView
    mrzScanView.setScanViewConfig(scanViewBaseConfig);
    //set the scanViewPlugin to the ScanView
    mrzScanView.setScanViewPlugin(scanViewPlugin);
    //add the result listener
    scanViewPlugin.addScanResultListener(new ScanResultListener<ScanResult<ID>>() {
                    @Override
                    public void onResult(ScanResult<ID> idScanResult) {
                            Identification identification = (Identification) idScanResult.getResult();
                            identification.toJSONObject();

                            //set the path of the mrz Image
                            String path = setupImagePath(idScanResult.getCutoutImage());



                            startScanResultIntent(getResources().getString(R.string.title_mrz), getIdentificationResult(identification), path);
                            setupScanProcessView(ScanMrzActivity.this, idScanResult, getScanModule());
                    }


            });

New JSON Configuration

For Anyline 4, there is a new JSON file structure. The JSON file must contain now the viewPlugin field. Optionally it may contain the plugin field which is initialising internally the specific Scan Plugin. The list of parameters are described in: View Configuration as well as the call for JSON file can be found at: Android View Configuration