On this page

Stuck? Open a support ticket and the barKoder team will help. Open a ticket

Cordova Installation

Before you start #

Requirements #

You need Node.js, the Cordova CLI and the native tools for the platforms you build for.

Node.js and npm #

Cordova is installed through npm, which comes bundled with Node.js.

Download Node.js (Cordova comes from npm, which comes with it), then check both versions:

Shell
node -v  
npm -v

Mobile Development SDKs #

To build and run the app you need Xcode (macOS only) for iOS and Android Studio for Android. cordova build android also needs JDK 17 or later, with JAVA_HOME set, and Gradle: it runs the gradle command to make the project's Gradle wrapper.

Make a Cordova app #

Install the Cordova CLI, make an app with both platforms and build it once:

Shell
# Install Cordova globally
npm install -g cordova  

# Verify Cordova installation
cordova -v  

# Create a test project
cordova create myApp com.example.myapp MyApp  
cd myApp  

# Add platforms (optional)
cordova platform add ios  
cordova platform add android  

# Build the app to ensure everything works
cordova build

If the build finishes without errors, your setup is complete. The steps below are in this app's folder.

1. Add the package #

Install #

Shell
cordova plugin add barkoder-cordova

Install Manually #

To install from a local folder instead:

  • Download the plugin from Downloads in the barKoder Developer Portal
  • Unpack it and rename the folder if you like (for example barkoder-cordova)
  • Move the folder anywhere outside the project folder
  • Add it to the project:
Shell
cordova plugin add "/your-path/barkoder-cordova"

2. Set the license key and barcode types #

Licensing #

Without a valid license key the SDK still scans, but each result starts with (Unlicensed) and part of its data is replaced with dots. Get a free trial key on the trial page: choose Native or WASM and enter your app ID (for the Web SDK, your domain). A trial key lasts 30 days, for up to 25 devices, one per app ID. For a production license, request a quote. By using the SDK you agree to the End User License Agreement.

In the code of step 3, the key goes in Barkoder.registerWithLicenseKey, before Barkoder.initialize, and setActiveBarcodeTypes() turns on the barcode types you scan.

3. Start scanning and read results #

Using the plugin #

The code below is an Angular component. Make the Angular app in your Cordova project's folder (as on the Angular integration example), with its build going to the Cordova project's www folder:

Shell
npx @angular/cli new angular_app --style=scss --ssr=false
cd angular_app
npx ng config projects.angular_app.architect.build.options.outputPath '{"base":"../www","browser":""}'

In the Angular app's src/index.html, load cordova.js before </head>: it puts the plugin on window.Barkoder and fires deviceready.

HTML
<script src="cordova.js"></script>

Angular Example #

In your component's ts file (the declare and import lines at the top, the rest inside the component class):

TypeScript
declare var Barkoder: any;
import { ElementRef, ViewChild } from '@angular/core';
import { BarcodeType } from 'barkoder-cordova/www/BarkoderConfig';

@ViewChild('barkoderView') barkoderViewRef!: ElementRef;

  setActiveBarcodeTypes() {
   Barkoder.setBarcodeTypeEnabled(BarcodeType.code128, true);
   Barkoder.setBarcodeTypeEnabled(BarcodeType.ean13, true);
  }

  setBarkoderSettings() {
   Barkoder.setRegionOfInterestVisible(true);
   Barkoder.setRegionOfInterest(5, 5, 90, 90);
   Barkoder.setCloseSessionOnResultEnabled(false);
   Barkoder.setImageResultEnabled(true);
   Barkoder.setBarcodeThumbnailOnResultEnabled(true);
   Barkoder.setBeepOnSuccessEnabled(true);
   Barkoder.setPinchToZoomEnabled(true);
   Barkoder.setZoomFactor(2.0);
  }

  async startScanning() {
   const boundingRect = this.barkoderViewRef.nativeElement.getBoundingClientRect() as DOMRect;
   Barkoder.registerWithLicenseKey("your_license_key");
   await Barkoder.initialize(
       Math.round(boundingRect.width),
       Math.round(boundingRect.height),
       Math.round(boundingRect.x),
       Math.round(boundingRect.y))

   this.setBarkoderSettings();
   this.setActiveBarcodeTypes();

   Barkoder.startScanning((barkoderResult: any) => {
     barkoderResult.decoderResults.forEach((result: any) => console.log("Result: " + result.textualData));
   }, (err: any) => {
     console.log(err);
   });
  }

In your component's HTML file add the barkoderView element, and a button that starts scanning:

HTML
<div id="barkoderView" #barkoderView></div>
<button (click)="startScanning()">Start scanning</button>

In your scss file set the desired barkoderView height:

CSS
#barkoderView {
  height: 400px;
}

Build the Angular app into www, then build and run the Cordova app (again after every change):

Shell
npx ng build
cd ..
cordova build android
cordova run android