###Demo
Install CV-Demo.apk to your phone and log in with the test account.
Download the UI module source code according to the type of Google library your project depends on, unzip it and copy the
liveness
folder to your project as a normalmodule
for dependency.
If pulling aar fails, we recommend trying the following:
If your gradle version is less than 7.0, add the maven repository to the project's root build.gradle
:
xxxxxxxxxx
allprojects {
repositories {
...
maven { url 'http://public-n3.advai.net/repository/maven-releases/' }
}
}
If your project's gradle version is greater than 7.0, add a maven repository to the project's root directory settings.gradle
:
xxxxxxxxxx
dependencyResolutionManagement {
...
repositories {
...
maven {
url 'http://public-n3.advai.net/repository/maven-releases/'
allowInsecureProtocol = true
}
}
}
If the above still does not pull the aar, you can download the aar from the following link and manually depend on it for your project:
The links below are for lib 2.2.0 and core 4.5. Modify the version number in the link to download the corresponding version.
Initialization SDK.
xxxxxxxxxx
// 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
xxxxxxxxxx
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.
xxxxxxxxxx
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 need to give the livenessId to your server, and the server will call openAPI to get the score of this test.
You can get the image directly through the methods provided by the SDK, or you can call the openAPI from the server.
xxxxxxxxxx
/**
* 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:
xxxxxxxxxx
// 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
xxxxxxxxxx
// 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.
xxxxxxxxxx
GuardianLivenessDetectionSDK.capturePictureQueue(true);
Obtain image sequence (obtained after successful live detection):
xxxxxxxxxx
List<String> imageSequenceList = LivenessResult.getImageSequenceList();
Customized action time
Detection time for custom actions, all actions take effect after setting, unit: Millisecond
xxxxxxxxxx
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.
xxxxxxxxxx
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
xxxxxxxxxx
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
xxxxxxxxxx
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.
xxxxxxxxxx
<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:
xxxxxxxxxx
android.enableJetifier=true
SDK Compatibility
armeabi-v7a
,arm64-v8a
,x86
,x86_64
,armeabi
errorCode | raw native sdk code | Description |
---|---|---|
PREPARE_TIMEOUT | fail_reason_prepare_timeout | Timeout during the preparation stage |
ACTION_TIMEOUT | fail_reason_timeout | Timeout during the motion stage |
MULTIPLE_FACE | fail_reason_muti_face | Multiple faces detected during the motion stage |
FACE_MISSING | fail_reason_facemiss_blink_mouth | Face is missing during the motion stage(blink or open mouth) |
FACE_MISSING | fail_reason_facemiss_pos_yaw | Face is missing during the motion stage(pos yaw) |
MUCH_ACTION | fail_reason_much_action | Multiple motions detected during the motion stage |
USER_GIVE_UP | user_give_up | The user clicked the top left back button during the detection process |
NO_RESPONSE | Network request failed | |
DEVICE_NOT_SUPPORT | device_not_support | The front camera of this device cannot be opened |
UNDEFINED | Other undefined errors | |
AUTH_PARAMETER_ERROR | Authentication Error: Please ensure that the license has been initialized successfully. | |
AUTH_BAD_NETWORK | Authentication network request failed | |
AUTH_IAM_FAILED | Authentication Error: Please ensure that the license has been initialized successfully. | |
...(Other server side error codes) |