Plugins

To make it easier for developers to implement the Anyline SDK, it is based on Plugins. You can use these Plugins to implement your scanning use case into your application.

This section describes how to implement and use the Anyline SDK plugins in Android.

General Plugin Implementation

Note

All the examples provided here are based on the Meter Plugin. Specific implementations can be found in the next section, and in the Android API Reference.

How to implement an Anyline Plugin

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

Note

Starting with version 5, in Android the ScanPlugin can be also initialized explicitely and give it as parameter to ScanViewPlugin. Example can be found at Driving License.

  • 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, or just with a scanViewPlugin (internally the ScanPlugin will be instantiated depending on ScanViewPlugin type)
  • 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.

Overview

Setting up your Plugin is done with the following steps:

  1. Add the plugin view to your xml layout
  2. Instantiate the view in the onCreate() method of your Activity
  3. Set your view configuration on the view in
  4. Initialise the view in the onCreate() method of your Activity
  5. Start scanning in the onResume() method of your Activity
  6. Stop scanning in the onPause() method of your Activity

Anyline ScanPlugin

Initialise the Anyline SDK Plugin

The plugin concept is divided in ScanView, ScanViewPlugin and ScanPlugin.

On Android, the ScanViewPlugins are Views, that can be added to your layout xml.

Add the ScanView to the layout
<!--
  ~ Anyline
  ~ activity_scan_energy.xmll
  ~
  ~ Copyright (c) 2015 9yards GmbH
  ~
  -->

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_layout"
    android:animateLayoutChanges="true">


    <io.anyline.view.ScanView
        android:id="@+id/scan_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

In the next step, go to your Java Activity code and get the view from the layout in onCreate() or onActivityCreated()

Get the ScanView
        // get the view from the layout (check out the xml for the configuration of the view)
        energyScanView = (ScanView) findViewById(R.id.scan_view);

Anyline ScanViewPlugin

Initialise the Scan View Plugin

After getting the ScanView, the next step is to initialise the Scan View Plugin. The ScanViewPlugin will handle and display the UI used for scanning. Together with your Anyline License Key Generation, you can now initialise MeterScanViewPugin. The MeterScanViewPugin will internally initialize the BarcodeScanPlugin. In java, this should be called in onCreate() or onActivityCreated(). On Android, the ScanViewPlugin will internally instantiate a ScanPlugin of the same type.

Initialize the ScanViewPlugin
        //init the scanViewPlugin configuration which hold the scan view ui configuration (cutoutConfig and ScanFeedbackConfig)		
	ScanViewPluginConfig energyScanviewPluginConfig = new ScanViewPluginConfig(getApplicationContext(), "energy_view_config.json");

ScanView

Set the Base Configuration

The base configurations are holding the camera and the flash properties. You can set it the following way, also in onCreate() or onActivityCreated()

Set the Base Configuration(Camera and Flash configuration) and the View Configuration (Cutout and ScanView configuration)
	//init the scan view
	MeterScanViewPlugin scanViewPlugin = new MeterScanViewPlugin(getApplicationContext(), energyScanviewPluginConfig, "METER");
	//init the base scanViewconfig which hold camera and flash configuration
	BaseScanViewConfig energyBaseScanViewConfig = new BaseScanViewConfig(getApplicationContext(), "energy_view_config.json");

Set the ScanViewPlugin to the ScanView

A ScanView is holding a ScanViewPlugin, therefore a ScanViewPlugin has to be set to the ScanView.

Set the ScanViewPlugin to the ScanView
	//set the base scanViewConfig to the ScanView
	energyScanView.setScanViewConfig(energyBaseScanViewConfig);

Start Scanning

After everything is initialised, you can start the scanning process, by calling start() on the meterScanView. It is advised to place this call in the onResume() lifecycle method of Android.

startScanning
    @Override
    protected void onResume() {
        super.onResume();
        //start the actual scanning
        energyScanView.start();
    }

Stop Scanning

To stop the scanning process, call stop() on the meterScanView.

To make sure the SDK is properly stopped upon leaving the Activity, make sure to place cancelScanning() and releaseCamera()/releaseCameraInBackground() in the onPause() lifecycle method of Android.

stopScanning
    @Override
    protected void onPause() {
        super.onPause();
        //stop the scanning
        energyScanView.stop();
        //release the camera (must be called in onPause, because there are situations where
        // it cannot be auto-detected that the camera should be released)
        energyScanView.releaseCameraInBackground();
    }

Simultaneous Barcode Scanning

As of version 3.8, each Plugins supports parallel barcode scanning.

The implementation details can be found at Simultaneous Barcode Scanning.

Check license Expiry Date

New in version 3.24.

The ALCoreController provides a static method to check the expiry date from a license key string. A string containing the date will be returned. If the license cannot be parsed, an error will be returned.

Check License Expiry Date
String dateString = AnylineController.getLicenseExpirationDate(string YOUR_LICENSE_KEY_STRING);
// Handle Error after.

Plugin Specifics

Currently there are six plugins

Anyline OCR Plugin

With the AnylineOCR Plugin, you have the ability to create your own OCR use case, on the fly with almost no effort. It offers a variety of parameters for you to adjust the scanning process to your use case. Our Bottlecap, Shipping Container, Universal Serial Number and Vehicle Identification Number scanners are all use cases implemented with the AnylineOCR Plugin.

Anyline OCR Plugin    
Anyline OCR Documentation of the Plugin Android Plugin Implementation Details

Meter Plugin

The Anyline Energy plugin is capable of scanning Analog Electric-, Gas- and Water Meter readings. It is also possible to scan Bar- and QR-codes, which is useful for identifying meters, as well as the Serial Number. Common Digital Meters and Heat Meters can also be scanned.

Meter Plugin    
Meter Documentation of the Plugin Android Plugin Implementation Details

ID Plugin

The Anyline ID plugin provides the functionality to scan passports and other IDs holding a Machine Readable Zone (MRZ). Additionally this plugin is also capable to scan Driving Licenses.

ID Plugin    
ID Documentation of the Plugin Android ID Plugin Implementation Details

Barcode Plugin

With the Anyline Barcode-Plugin 23 different formats of Bar- and QR-Codes can be scanned.

Barcode Plugin    
Barcode Documentation of the Plugin Android Plugin Implementation Details

Document Plugin

The Anyline Document Plugin detects document outlines, validates the angles of the document to ensure the it is not too skewed, determines the sharpness of the text and rectifies the document.

Document Plugin    
Document Documentation of the Plugin Android Plugin Implementation Details

License Plate Plugin

With the Anyline License Plate Plugin provides functionality to scan a variety of license plates from different countries.

License Plate Plugin    
License Plate Documentation of the Plugin Android Plugin Implementation Details

Tire Plugin

With the Anyline Tire Plugin, Tire Identification Numbers (TIN), Tire Size and Commercial Tire IDs can be scanned.

Tire Plugin    
Tire Documentation of the Plugin Android Plugin Implementation Details