Get Started With The Parser#

The parser parses data strings, e.g. as found in barcodes, into a set of key-value mappings. These data formats are supported: Health Industry Bar Code (HIBC), GS1 Application Identifier (parser/AI) system, AAMVA Driver License/Identification, ICAO Machine Readable Travel Document (parser/MRTD) and Swiss QR Codes, VIN Vehicle Identification Number.

More data formats will be added in future releases. Please contact us if the data format you are using is not yet supported, or you want to use the parser on a currently unsupported platform.

Prerequisites#

Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you added the necessary dependencies. If you have not done that yet, check out this guide.

Note

You can retrieve your Scandit Data Capture SDK license key, by signing in to your account at ssl.scandit.com.

First of all, include the ScanditParser library and its dependencies to your project, if any.

External dependencies#

The Scandit Data Capture SDK modules depend on a few standard libraries that you can find listed below. If you are including the Scandit Data Capture SDK through Gradle or Maven, all of these dependencies are automatically pulled in and there is no need for you to do anything further. If on the other hand you are directly adding the AAR files to the project, you will have to add these dependencies yourself.

Module

Dependencies

ScanditCaptureCore.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

  • com.squareup.okhttp3:okhttp:3.12.10

ScanditBarcodeCapture.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

ScanditParser.aar

No dependencies

ScanditTextCaptureBase.aar

No dependencies

ScanditTextCapture.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

ScanditIdCapture.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

Internal dependencies#

Some of the Scandit Data Capture SDK modules depend on others to work:

Module

Dependencies

ScanditCaptureCore

No dependencies

ScanditBarcodeCapture

  • ScanditCaptureCore

ScanditParser

No dependencies

ScanditTextCaptureBase

No dependencies

ScanditTextCapture

  • ScanditCaptureCore

  • ScanditTextCaptureBase

ScanditIdCapture

  • ScanditCaptureCore

  • ScanditTextCaptureBase (MRZ or VIZ documents)

  • ScanditTextCapture (MRZ documents)

Create the Data Capture Context#

The first step to add barcode capture capabilities to your application is to create a new data capture context. The context expects a valid Scandit Data Capture SDK license key during construction.

DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");

Use the Parser#

In a nutshell, the parser provides functionality to transform a data string and into a list of key-value pairs. To use this functionality in your app, first the parser must be instantiated with the desired format. The result is then returned in a result object. The following sample shows how the parser code typically looks like.

import com.scandit.datacapture.parser.*;

 ...
 Parser parser = Parser.forFormat(dataCaptureContext, ParserDataFormat.GS1_AI);

 ParsedData res = null;
 try {
     res = parser.parseString("1719060110SCANDIT123");
 } catch (IllegalArgumentException e) {
     // Something went wrong.
 }

 // We can either access the data from the raw JSON string ...
 Log.d("JsonString", res.getJsonString());

 // ... or from the fields dictionary ...
 Map<String, ParsedField> map = res.getFieldsByName();
 ParsedField metaField = map.get("17");
 Log.d("FieldRawString", metaField.getRawString());
 // parsed can be a Map<String,Object>, Object[], Integer, Long, Boolean, Double or String
 Object parsed = metaField.getParsed();
 Log.d("OUTPUT", parsed.toString());

 // ... or from the fields array
 List<ParsedField> fields = res.getFields();
 for (ParsedField field : fields){
     final String result = field.getName() + ": " + field.getParsed();
     Log.d("OUTPUT", result);
 }

For details, go to the API docs.