On this page

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

Capacitor Installation

Before you start #

Requirements #

You need Node.js, a web app to add Capacitor to, and the native tools for the platforms you build for.

Node.js and npm #

Capacitor 8 needs Node.js 22 or later; npm comes with it.

Download Node.js, 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. The Android build with Capacitor 8 needs JDK 21.

Add Capacitor to your web app #

Shell
npm install @capacitor/core
npm install -D @capacitor/cli
npx cap init "My App" com.example.myapp --web-dir dist/my-app/browser

Run these in your web app's folder (the General example is an Angular app: npx @angular/cli new my-app). Give npx cap init your app's name and ID. --web-dir is the folder your build writes the web app to; for an Angular app it is dist/<project name>/browser.

Add Platforms #

Shell
npm install @capacitor/android @capacitor/ios
npx cap add android
npx cap add ios

Build and Run on Platforms #

Build the web app and copy it into the native projects (again after every change), then open them in Android Studio or Xcode and run:

Shell
npm run build
npx cap sync
npx cap open android
npx cap open ios

1. Add the package #

Install #

Add the plugin to your app and copy it into the native projects:

BATCH
npm install barkoder-capacitor
npx cap sync

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.

Register the key before Barkoder.initialize, then turn on the barcode types you scan. The General example has the whole component.

TypeScript
import { Barkoder, BarcodeType } from 'barkoder-capacitor';

// before Barkoder.initialize(...)
Barkoder.registerWithLicenseKey({ licenseKey: "YOUR_LICENSE_KEY" });

// after Barkoder.initialize(...)
Barkoder.setBarcodeTypeEnabled({ type: BarcodeType.qr, enabled: true });
Barkoder.setBarcodeTypeEnabled({ type: BarcodeType.ean13, enabled: true });

3. Start scanning and read results #

Start scanning #

Each result comes to the barkoderResultEvent listener. Add it once, for example in your component's constructor, and start scanning after Barkoder.initialize, for example from a button:

TypeScript
import { Barkoder, BarkoderResult } from 'barkoder-capacitor';

// once, for example in the component's constructor
Barkoder.addListener('barkoderResultEvent', (data: any) => {
  const barkoderResult = new BarkoderResult(data);
  barkoderResult.decoderResults.forEach((result) => {
    console.log(result.textualData);
  });
});

// after Barkoder.initialize(...)
Barkoder.startScanning();

The General example has the whole Angular component: the view element, its size, the settings and the button.