Install CV-Demo.apk to your phone and log in with the test account.
If you want to use the default UI style, add the dependency to your project's /shared/build.gradle.kts
as follows:
...
android {
...
dependencies {
api("ai.advance.mobile-sdk.android:liveness-detection:2.1.8")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.constraintlayout:constraintlayout:2.1.4")
// The default UI library
api(":ai.advance.mobile-sdk.android:liveness-detection-ui:2.1.6@aar")
}
}
If you need to customize the UI, follow these steps:
liveness-kotlin/liveness/src/main/kotlin/ai
folder to shared/src/androidMain/kotlin
.liveness-kotlin/liveness/src/main/res
folder toshared/src/androidMain/
,If the res
folder already exists in the androidMain
folder, you need to manually merge the contents of the two res
folders.Copyliveness-kotlin/liveness/src/main/AndroidManifest.xml
folder toshared/src/androidMain/
,If the AndroidManifest.xml
file already exists in the androidMain
folder, open the existing file and register the LivenessActivity
in the
Open the settings.gradle.kts
file in the root directory and add the following maven repository configuration:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://public-n3.advai.net/repository/maven-releases/")
}
}
}
Open /shared/build.gradle.kts
and add the following dependencies:
...
android {
...
dependencies {
api("ai.advance.mobile-sdk.android:liveness-detection:2.1.8")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.constraintlayout:constraintlayout:2.1.4")
}
}
Initialization SDK.
// The last boolean value represents whether the Global service is enabled or not, and is set to true if it is, or false if it is not.
// The init method need to be called in your application class
GuardianLivenessDetectionSDK.init(this,your market,false);
Set movement difficulty level(Called before the setLicenseAndCheck() method, otherwise it does not take effect)
You can specify the difficulty of the action detection according to your business requirements (EASY,NORMAL,HARD),default level is NORMAL
GuardianLivenessDetectionSDK.setDetectionLevel(GuardianLivenessDetectionSDK.DetectionLevel.EASY);
Check license
The license is obtained by your server calling our openAPI, you need to check license before starting the liveness detection activity.
String license = "xxx";
String checkResult = GuardianLivenessDetectionSDK.setLicenseAndCheck(license);
if ("SUCCESS".equals(checkResult)) {
// license valid
startLivenessActivity();
} else {
// license is not available, expired/wrong format/appId not filed
}
Start the liveness detection test and obtain the test result.
The camera detection permission is not processed on the live detection page. Please do the permission detection before entering the page. Each time the liveness detection is successful, a unique livenessId and a clear photo of 600*600 pixels for this test will be returned.
You can get the image directly through the methods provided by the SDK, or you can call the openAPI from the server.
/**
* requestCode
*/
public static final int REQUEST_CODE_LIVENESS = xxxx;
/**
* start Liveness Activity
*/
private void startLivenessActivity() {
Intent intent = new Intent(this, LivenessActivity.class);
// Set camera type, default is front camera
GuardianLivenessDetectionSDK.setCameraType(CameraType.FRONT);// The back camera is CameraType.BACK
startActivityForResult(intent, REQUEST_CODE_LIVENESS);
}
/**
* get Liveness result
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_LIVENESS) {
if (LivenessResult.isSuccess()) {// Success
String livenessId = LivenessResult.getLivenessId();// livenessId
boolean pay = LivenessResult.isPay();// pay status
Bitmap livenessBitmap = LivenessResult.getLivenessBitmap();// picture
} else {// Failure
String errorCode = LivenessResult.getErrorCode();// error code
String errorMsg = LivenessResult.getErrorMsg();// error message
String transactionId = LivenessResult.getTransactionId(); // Transaction number, which can be used to troubleshoot problems with us
...
}
}
}
Important Note to Order of Motions
The default action sequence is [Blink]->[Shake Head]. To customize, you can follow one of the methods:
// the first boolean value indicates if the given actions should be shuffled.
GuardianLivenessDetectionSDK.setActionSequence(true,Detector.DetectionType.POS_YAW, Detector.DetectionType.MOUTH, Detector.DetectionType.BLINK);
Customize the size of the returned image
// Settable input range: [300,1000], unit: pixels
GuardianLivenessDetectionSDK.setResultPictureSize(600);
Return multiple images (off by default)
The SDK supports capturing a separate image for each action. If you turn this switch on, the SDK will run with a higher memory footprint due to the extra images being captured. If your App is already using a lot of memory, turning on this configuration may cause a memory overflow, so please choose carefully.
GuardianLivenessDetectionSDK.capturePictureQueue(true);
Obtain image sequence (obtained after successful live detection):
List<String> imageSequenceList = LivenessResult.getImageSequenceList();
Customized action time
Detection time for custom actions, all actions take effect after setting, unit: Millisecond
GuardianLivenessDetectionSDK.setActionTimeoutMills(10000);
User binding (strongly recommended).
You can use this method to pass your user unique identifier to us, we will establish a mapping relationship based on the identifier.It is helpful for us to check the log when encountering problems.
GuardianLivenessDetectionSDK.bindUser(String userId)
Turn on occlusion detection
If you want to enable occlusion detection, please call the following method after initializing the SDK to set it
GuardianLivenessDetectionSDK.isDetectOcclusion(true)
Multilingual
Currently SDK supports six languages/voice: Chinese, English, Indonesian, Vietnamese,Hendi,Thai.Automatically switch according to the current language of the mobile phone, no code setting is required..
If the SDK does not automatically switch with the system language, please check your cellphone language settings and make sure that both [Region] and [Language] are switched to the corresponding language.
If it still have problems with multiple languages and the app only supports one language, you can filter out the unwanted languages by adding the following configuration to build.gradle
android {
defaultConfig {
...
resConfigs("in-rID") // For example, only Indonesian is supported
}
}
Runtime Permissions
This SDK requires the following permissions, which have been configured in the aar manifest file and the SDK itself is ready for dynamic application of Android 6.0+ permissions.
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
About App Bundle Bundling
Please verify that the packaged APK will work on all architectures of cell phones. If you are prompted with [this device is not supported], it means that the .so file in .aar is missing when assembling the APK. Please contact us for a separate version of .so and .aar.
Code proguard configuration
The SDK already has code proguard, no additional configuration is required.
About androidx
Considering the mutually exclusive nature of AndroidX
and android.support.*
packages, all the .aar of this SDK are android.support.*
packages. If your project is an AndroidX
package and you encounter a android.support.*
package conflict error when compiling, please add the following configuration to the gradle.properties
file in the root directory of your project and recompile the project and you will be able to:
android.enableJetifier=true
SDK Compatibility
armeabi-v7a
,arm64-v8a
,x86
,x86_64
,armeabi
Error Code:
code |
---|
FACE_MISSING |
ACTION_TIMEOUT |
MULTIPLE_FACE |
MUCH_MOTION |
AUTH_BAD_NETWORK |
CHECKING_BAD_NETWORK |
DEVICE_NOT_SUPPORT |
USER_GIVE_UP |
UNDEFINED |
NO_RESPONSE |
AUTH_PARAMETER_ERROR |
AUTH_IAM_FAILED |