Get Started
In this guide you will learn step-by-step how to add Barcode Capture to your application.
The general steps are:
- Include the ScanditBarcodeCapture library and its dependencies to your project, if any.
- Create a new data capture context instance, initialized with your license key.
- Create a barcode capture settings and enable the barcode symbologies you want to read in your application.
- Create a new barcode capture mode instance and initialize it with the settings created above.
- Register a barcode capture listener to receive scan events. Process the successful scans according to your application’s needs, e.g. by looking up information in a database. After a successful scan, decide whether more codes will be scanned, or the scanning process should be stopped.
- Obtain a camera instance and set it as the frame source on the data capture context.
- Display the camera preview by creating a data capture view.
- If displaying a preview, optionally create a new overlay and add it to data capture view for a better visual feedback.
Create the Data Capture Context
The first step to add 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.
const context = ScanditCore.DataCaptureContext.forLicenseKey(
'-- ENTER YOUR SCANDIT LICENSE KEY HERE --'
);
Configure the Barcode Scanning Behavior
Barcode scanning is orchestrated by the BarcodeCapture data capture mode. This class is the main entry point for scanning barcodes. It is configured through BarcodeCaptureSettings and allows to register one or more listeners that will get informed whenever new codes have been recognized.
For this tutorial, we will setup barcode scanning for a small list of different barcode types, called symbologies. The list of symbologies to enable is highly application specific. We recommend that you only enable the list of symbologies your application requires.
const settings = new ScanditBarcode.BarcodeCaptureSettings();
settings.enableSymbologies([
ScanditBarcode.Symbology.Code128,
ScanditBarcode.Symbology.Code39,
ScanditBarcode.Symbology.QR,
ScanditBarcode.Symbology.EAN8,
ScanditBarcode.Symbology.UPCE,
ScanditBarcode.Symbology.EAN13UPCA,
]);
If you are not disabling barcode capture immediately after having scanned the first code, consider setting the BarcodeCaptureSettings.codeDuplicateFilter to around 500 or even -1 if you do not want codes to be scanned more than once.
Next, create a BarcodeCapture instance with the settings initialized in the previous step:
const barcodeCapture = ScanditBarcode.BarcodeCapture.forContext(
context,
settings
);
Register the Barcode Capture Listener
To get informed whenever a new code has been recognized, add a BarcodeCaptureListener through BarcodeCapture.addListener() and implement the listener methods to suit your application’s needs.
First implement the BarcodeCaptureListener interface. For example:
const listener = {
didScan: (barcodeCapture, session) => {
const recognizedBarcodes = session.newlyRecognizedBarcode;
// Do something with the barcodes
},
};
Then add the listener:
barcodeCapture.addListener(listener);