Getting Started with Infinity Plugins
This guide walks you through installing the Anyline Infinity Plugin, initializing the SDK, and running your first scan.
Prerequisites
-
A valid Anyline license key. Obtain one by following the License Key Generation guide.
Every license is bound to a Bundle Identifier. If you change your Bundle Identifier, you will require a new license. This also ensures that your license key cannot be used in any other application. -
Platform-specific requirements:
-
Cordova: Cordova 12+, cordova-ios 7+, cordova-android 13+
-
Step 1: Install the Plugin
-
Cordova
Add the Anyline plugin to your Cordova project:
cordova plugin add io-anyline-cordova
On Android, add the Anyline Maven repository. Create or edit platforms/android/app/build-extras.gradle:
repositories {
maven { url 'https://mobile-sdk-android.anyline.io/release/' }
}
Step 2: Import the Plugin
-
Cordova
The plugin is available as a global after installation via the clobbers target:
// Available globally via window.AnylineInfinity
var anylineInfinity = window.AnylineInfinity;
Step 3: Initialize the SDK
Initialize the Anyline SDK with your license key. This must be called before starting any scan.
-
Cordova
var request = {
licenseKey: 'YOUR_LICENSE_KEY', // Replace with your Anyline License Key
// Optional: only needed if your app bundles custom ML model files provided by Anyline.
// The value depends on where these files are placed in your project. See the Developer Examples.
assetPathPrefix: 'www/assets/anyline_assets',
};
anylineInfinity.requestSdkInitialization(
request,
function(response) {
if (response.initialized) {
console.log('SDK initialized:', response.succeedInfo);
} else {
console.error('SDK init failed:', response.failInfo.lastError);
}
},
function(error) {
console.error('SDK init error:', error);
}
);
Step 4: Prepare a ScanViewConfig
Create a ScanViewConfig JSON to define what and how to scan. See Constructing your Configuration JSON using JSON Schemas for details on building your configuration, and ScanViewConfig Documentation for the full schema reference.
{
"viewPluginConfig": {
"pluginConfig": {
"id": "barcode",
"barcodeConfig": {
"barcodeFormats": ["ALL"]
},
"cancelOnResult": true (1)
}
}
}
| 1 | cancelOnResult stops scanning after the first result. Set to false for continuous scanning. |
Save this JSON as a file in your app’s assets and load it as a string at runtime. The resulting string is the scanViewConfigJson used in Step 5.
|
Step 5: Start Scanning and Handle Results
Set up a result subscription, configure the scan request, and start the scan session. The scan session remains active until explicitly stopped or until the user dismisses the scan view. Results arrive as events during the session — you can receive zero or more results before the session ends.
-
Cordova
// Enums are available via window.AnylineEnums (merged by plugin.xml)
var ExportedScanResultImageFormat = AnylineEnums.ExportedScanResultImageFormat;
// 1. Configure how scan results are delivered
var scanResultConfig = {
imageContainer: {
encoded: {},
},
imageParameters: {
format: ExportedScanResultImageFormat.Png,
quality: 50,
},
};
// 2. Build the scan request
// scanViewConfigJson is a JSON string containing your ScanViewConfig
var request = {
scanViewConfigContentString: scanViewConfigJson,
scanResultConfig: scanResultConfig,
};
// 3. Start scanning with result callback
anylineInfinity.requestScanStart(
request,
function(response) {
// Called once when the scan session ends
console.log('Scan session ended:', response.status);
},
{
onScanResults: function(result) {
// Called 0..N times during scanning
var scanResults = result.exportedScanResults || [];
scanResults.forEach(function(scanResult) {
var pluginResult = scanResult.pluginResult;
console.log('Plugin result:', pluginResult);
});
},
}
);
In Cordova, the result callback is passed directly to requestScanStart. The subscription is set up as part of the scan start call.
|
See Scan Result Handling for details on result structure and image handling.
Step 6: Stop Scanning
The scan session ends naturally after the first result when cancelOnResult is set to true in the ScanViewConfig, or after all sub-plugin results are collected when using composite scanning. You only need to call requestScanStop for continuous scanning (cancelOnResult: false) or when you want to stop the session before any result is received.
|
Stop the active scan session programmatically:
-
Cordova
// Stop with default behavior
anylineInfinity.requestScanStop();
// Or stop with an optional reason (surfaces in abortInfo.message on the scan response)
anylineInfinity.requestScanStop({ message: 'Scan stopped: no result within timeout' });
Next Steps
-
Infinity Plugin API Reference (full method and event reference)
-
Scan Result Handling (working with scan results and images)
-
Advanced Topics (scan switching, UCR, and platform-specific tips)