Deprecation warning

Please note that this is outdated documentation for an older release of the Scandit Barcode Scanner SDK.

We are deprecating the 5.x API on all platforms (except Linux). Release 5.19 in April 2021 will be our final. Applications running 5.x will continue to work, and we will continue to release critical bug fixes and security patches only, for one year. We encourage you to migrate to 6.x and take advantage of our latest / advanced features and improved performance.

You'll find the updated documentation at: Data Capture SDK Documentation for Cordova

Integrate the Scandit SDK into your app

To integrate the Scandit Barcode Scanner into your Cordova app, follow the simple steps below.

Get the Scandit Barcode Scanner SDK

Choose a plan (e.g., “Consumer Apps”, "Professional Apps", or “Enterprise/OEM” plan) at http://www.scandit.com/pricing and download the Scandit Barcode Scanner SDK for Android from your account.

Download page


Create a new project

If you do not have a Cordova project yet, you should create a new one.

cordova create helloworld --id "com.scandit.helloworld"
cd helloworld
cordova platform add ios
cordova platform add android

Add the plugin to your project

Use the cordova CLI to add the plugin to your already existing project.

cd <directory of your project>
cordova plugin add <path to downloaded and unzipped plugin>

Add the type definitions (TypeScript only)

If you have a TypeScript project (e.g. Ionic, Angular, etc), you can declare Scandit the following way, so TypeScript knows that Scandit exists in the global scope:

```typescript declare let Scandit: any; ```

We suggest inserting this type declaration at the top of the file where you'll use Scandit.

The Scandit namespace is going to be added to the window object, so there's no need to import any module, the only requirement for TypeScript projects is just to let the compiler know that Scandit exists in the global scope, so your project can compile properly.

As a more complex solution, you can also drop a type definition file (from types/index.d.ts) into your project. Depending on your TypeScript configuration, you might need to specify additional configuration options to make sure the TypeScript compiler is aware of the type definition file.

Instantiate and configure the barcode picker

The scanning process is managed by the BarcodePicker. Before instantiating the picker, you will have to set your Scandit Barcode Scanner license key. The key is available from your Scandit Barcode Scanner SDK account at http://account.scandit.com in the License Keys section. The barcode scanning is configured through an instance of scan settings that you pass to the BarcodePicker constructor.

// Set your license key.
Scandit.License.setAppKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");
var settings = new Scandit.ScanSettings();
settings.setSymbologyEnabled(Scandit.Barcode.Symbology.UPC12, true);
settings.setSymbologyEnabled(Scandit.Barcode.Symbology.EAN8, true);
// Instantiate the barcode picker by using the settings defined above.
var picker = new Scandit.BarcodePicker(settings);

Show the scan UI

Show the scanner to the user through show(success, manual, failure). You can pass it three callback functions, one for when a barcode is recognized, one for when a code was manually entered and one for when the scan process was canceled by the user.

picker.show(success, null, failure);

For more information on the different ways to add the barcode picker to your view hierarchy, consult android-scanview-options.

Add callbacks to handle the scanning event

You now need to define the functions that are referenced in the show() call. All functions take one argument.

function success(session) {
alert("Scanned " + session.newlyRecognizedCodes[0].symbology + " code: " + session.newlyRecognizedCodes[0].data);
// If you are using continuous scanning you might want to stop here. Please note that
// you will have to use session.stopScanning()/session.pauseScanning() instead of the
// corresponding method on the picker. This will avoid a race condition and immediately stop
// the scanning process after the success callback has finished executing.
session.stopScanning();
}
function manual(content) {
alert("Manual: " + content);
}
function failure(error) {
alert("Failed: " + error);
}

Show the picker and start the scanner

Start the actual scanning process to start the camera and look for codes.

picker.show(success, manual, failure);
picker.startScanning();

Build and run the app

Compile your project. Attach a device and run the app on your desired plattform.

cordova build
cordova run android
cordova run ios
cordova run windows

Build with PhoneGap Build (cloud service)

Phonegap Build only supports open source plugins. If you want to use PhoneGap Build, you will have to add our plugin yourself.

Steps to use our plugin with Phonegap Build:

  1. Download the Barcode Scanner SDK for Phonegap (https://ssl.scandit.com/sdk).
  2. Add the project on GitHub as a private repository. Make sure the repository is a private repository as we do not allow our plugins to be published.
  3. Link your PhoneGap Build account with your GitHub account to get the private repository. You can do so here: https://build.phonegap.com/apps, by clicking the link suggesting to link your account with a GitHub account.
  4. Add the plugin in the config.xml file: <gap:plugin spec="https://<token>@github.com/<username>/scandit-barcodescanner.git" source="git" />.
  5. Build the app.

Next steps