Integration Documentation for Cordova Compatible with Liveness Detection V4.x Version.
Minimum Android version:4.4 (API Level:19)
Compilation Android SDK version:API Level:35
Target Android SDK version:API Level:35
Supported CPU architectures:armeabi-v7a,arm64-v8a
SDK incremental package size:4.5MB+
If you have requirements for package size, you can refer to this to reduce the package size by approximately 1.4MB.
Capture image size:default capture image resolution 600px*600px, size is about 300KB, support custom image size range: 300px~1000px
Supported languages:
Use-permissions
xxxxxxxxxx<uses-feature android:name="android.hardware.camera" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.CAMERA" />
SDK requirements and limitations as below:
Nonearm64, x86_646.4MB(arm64, disable bitcode)NOen, zh-Hans, id, vi, th, es, ms, hi,filNSCameraUsageDescriptionClick to view the compliance explanation
Install IDV-Demo.apk to your phone and log in with the test account.
If you are upgrading from an older version of the Liveness SDK, please refer to this document to understand the changes.
xxxxxxxxxx "dependencies" ... "liveness-plugin-cordova""^4.1.10" ,cordova plugin rm liveness-plugin-cordova if it has been integrated before cordova plugin add liveness-plugin-cordovaFor iOS, you need to do:
Run pod install to install the dependencies in your project.
Add camera usage description in Info.plist as bellow. Ignore this step if you have added those.
xxxxxxxxxx<key>NSCameraUsageDescription</key><string>Use the camera to detect the face movements</string>Initialization SDK.
xxxxxxxxxxvar liveness = cordova.plugins.liveness;var market = liveness.Market.Indonesia;liveness.initSDKOfMarket(market, function () {}, function (error) {})Check license
The license is obtained by your server calling our openAPI, you need to check license before starting the liveness detection activity.
xxxxxxxxxxconst license = "xxx";liveness.setLicenseAndCheck(license, function (result) { if ("SUCCESS" === result) { var livenessParams = {
}; liveness.startLivenessDetection( livenessParams, function (livenessResult) { // display the result }, function (error) { console.error("Liveness Detection Failed.", error); } ); } }, function (error) { console.error("License Set Failed.", error); });
The returned values of checkResult:
APPLICATION_ID_NOT_MATCH: The package name is not within the authorized scope, please check your package name.
LICENSE_EXPIRE: The license has expired, please confirm that the user has calibrated the phone time.
ERROR_LICENSE(1): The license parsing succeeded, but necessary authentication information is missing, this case generally will not occur.
ERROR_LICENSE(2): The license parsing succeeded, but the internal format is incorrect, this case also generally will not occur.
ERROR_LICENSE(3): It is highly likely that an incompatible SDK license is being used, such as using an IQA license for liveness detection.
ERROR_LICENSE(4, 5): Parsing failed, please check if the license has issues like mismatched quotes, line breaks, etc.
You can create SDK launch parameters using the method below. Note that the function below is a complete example, including the SDK initialization and license check mentioned above. You can refer to it directly.
xxxxxxxxxxfunction startWithLicense(license) { if (!license) { showMessage('license is empty', 'error'); return; }
if (cordova && cordova.plugins && cordova.plugins.liveness) { console.log("success"); } else { showMessage("error", 'error'); return; } // Assign the plugin to a shorter variable for convenience var liveness = cordova.plugins.liveness;
// Use the Market enum for type safety and code completion var market = liveness.Market.Indonesia; // 1. Init SDK liveness.initSDKOfMarket(market, function () { // 2. Check license liveness.setLicenseAndCheck(license, function (result) { if ("SUCCESS" === result) { // 3. Configure liveness params then present SDK page const livenessParams = { cameraType: 'FRONT', queryId: 'your_query_id', // Replace with your query ID ticket: 'your_ticket', // Replace with your ticket detectOcclusion: false, // Whether to detect occlusion auditImageConfig: { enableCollectSwitch: true, // Whether to enable the collection switch imageWidth: 400, // Image width imageQuality: 30, // Image quality relativeSecondsCaptureAfterCameraLaunched: 3.0, // Capture at a relative number of seconds after the camera is launched }, livenessType: 'test_more', // Liveness detection type signatureId: '', // Signature ID, if available distantNearTimeout: 50000, // Timeout for distant-near detection in milliseconds silentTimeout: 50000, // Timeout for silent detection in milliseconds actionTimeout: 10000, // Timeout for actions in milliseconds prepareMillSeconds: 0, // Preparation time in milliseconds resultPictureSize: 600, // Result picture size maxRecordVideoSeconds: 600, // Maximum video recording time in seconds userId: '', // User ID maskColor: '#000000', // Mask color ovalColor: '#000000', // Oval color ovalNormalColor: '#000000', // Normal oval color }; liveness.startLivenessDetection( livenessParams, function (result) { console.log("Step 3: Liveness Detection Completed Successfully.", result);
// Display the result var resultContainer = document.getElementById('result-container'); var resultText = document.getElementById('result-text');
if (resultContainer && resultText) { resultText.textContent = JSON.stringify(result, null, 2); resultContainer.style.display = 'block'; } }, function (error) { showMessage("Failed: " + error, 'error'); } ); } }, function (error) { console.error("License Set Failed.", error); } ); }, function (error) { console.error("SDK Initialization Failed.", error); });}The following customization options are currently supported on iOS only.
Set the SDK display language via the language parameter. Supported values: "en", "zh-Hans", "id", "vi", "th", "es", "ms", "hi", "fil". If not set, the SDK follows the device system language.
xxxxxxxxxxconst livenessParams = { language: 'en',};Use localizedStrings to override specific SDK prompt texts. Keys follow the format "<language>.<key>". Only entries matching the effective language (from language or system language) are applied.
xxxxxxxxxxconst livenessParams = { language: 'en', localizedStrings: { 'en.no_face': 'No face detected', 'en.pls_blink': 'Please blink slowly', 'en.stay_still': 'Hold steady', },};Some commonly used keys (examples):
| Key | Default (en) |
|---|---|
no_face | Please put your face in the frame |
move_closer | Get closer |
move_further | Step back |
stay_still | Hold steady |
pls_blink | Please blink |
pls_open_mouth | Please open your mouth and then close |
low_light | Go to a brighter area |
warn_muti_face | Multiple faces detected from the image, please only keep one face in the image |
For the complete list of available keys, refer to the Localizable.strings file bundled with the SDK after running pod install:
xxxxxxxxxxPods/AAILivenessUI/AAILivenessSDK/AAILivenessUI/Resource/AAILanguageString.bundle/en.lproj/Localizable.strings
Use font to customize the font of the state-hint label. fontName must be a valid PostScript name of a font registered in your app. If the font cannot be found, the SDK default font is used.
xxxxxxxxxxconst livenessParams = { font: { fontName: 'YourCustomFont-Regular', fontSize: 16.0, },};See FAQ for Android UI customization.
See Error Code