Get Started With the ID Scanning#

This guide will briefly explain how to use the Scandit SDK for Id Scanning. Steps covered in this document are :

Supported documents#

Currently only AAMVA formats are supported for parsing data encoded in PDF417 barcodes. See more in: AAMVA Driver License/Identification. List of supported MRTD codes: ICAO Machine Readable Travel Document (parser/MRTD).

Add DLID scanner and parser#

First what you need to do is to set a barcode scanner for reading PDF417 barcodes and DLID parser:

DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey(SCANDIT_LICENSE_KEY)
Camera camera = Camera.getDefaultCamera();
camera.applySettings(BarcodeCapture.createRecommendedCameraSettings());
dataCaptureContext.setFrameSource(camera);

BarcodeCaptureSettings barcodeCaptureSettings = new BarcodeCaptureSettings();
barcodeCaptureSettings.enableSymbology(Symbology.PDF417, true);
BarcodeCapture barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, barcodeCaptureSettings);

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

Then you need to implement the BarcodeCaptureListener interface and add it to BarcodeCapture:

class MyBarcodeCaptureListener implements BarcodeCaptureListener {
  @Override
  public void onBarcodeScanned(
    @NonNull BarcodeCapture barcodeCapture,
    @NonNull BarcodeCaptureSession session,
    @NonNull FrameData frameData
  ) {
      if (session.getNewlyRecognizedBarcodes().isEmpty()) return;

      Barcode barcode = session.getNewlyRecognizedBarcodes().get(0);
      String data = barcode.getData();

      try {
        ParsedData parsedData = parser.parseString(text);
        // Do something with parsedData.
      } catch (RuntimeException e) {
        message = e.getMessage();
      }
    }
    // Other callbacks omitted for brevity.
}
barcodeCapture.addListener(new MyBarcodeCaptureListener());

Add MRZ scanner and MRTD parser#

The MRTD parser needs regexes to be specified. You can find the list of regex patterns here.

String PASSPORT_REGEX = INSERT_REGEX_HERE;
String TD1_REGEX = INSERT_REGEX_HERE;
String REGEX = "("
  + PASSPORT_REGEX + "|"
  + TD1_REGEX
  // + other regexes...
  + ")";
String CHAR_WHITELIST = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<";

String SETTINGS_JSON = "{"
  + "\"regex\" : " + "\"" + REGEX + "\","
  + "\"characterWhitelist\" : " + "\"" + CHAR_WHITELIST + "\""
  + "}";

You need to set a text capture for reading MRZ and a MRTD parser:

dataCaptureContext = DataCaptureContext.forLicenseKey(SCANDIT_LICENSE_KEY);

camera = Camera.getDefaultCamera();
camera.applySettings(TextCapture.createRecommendedCameraSettings());
dataCaptureContext.setFrameSource(camera);

TextCaptureSettings textCaptureSettings = TextCaptureSettings.fromJson(SETTINGS_JSON);

textCapture = TextCapture.forDataCaptureContext(dataCaptureContext, textCaptureSettings);

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

Then you need to implement the TextCaptureListener interface and add it to TextCapture:

class MyTextCaptureListener implements TextCaptureListener {
@Override
public void onTextCaptured(
  @NotNull TextCapture mode, @NotNull TextCaptureSession session, @NotNull FrameData data
) {
  //Pause the running TextCapture while processing the captured text.
  textCapture.setEnabled(false);

  if (session.getNewlyCapturedTexts().isEmpty()) return;

  String text = capturedTexts.get(0).getValue();
  String message;

  try {
    ParsedData parsedData = parser.parseString(text);
    // Do something with parsedData.
  } catch (RuntimeException e) {
    message = e.getMessage();
  }

}
textCapture.addListener(new MyTextCaptureListener());