Install CV-Demo.apk to your phone and log in with the test account.
According to the react-native
library version your project depends on, download the corresponding SDK, unzip it and copy the liveness
folder to the android
directory, same level as the app
folder.
Modify the android/settings.gradle
file as follows to add a reference to the liveness
module
...
include ':app', ':liveness'
If your project's com.facebook.react:react-native
library version number is greater than or equal to 0.60.0, you need to add the following configuration to your android/gradle.properties
file
android.enableJetifier=true
Modify the android/app/build.gradle
file to add library dependencies, and then synchronize gradle
to complete the SDK dependency configuration
...
android {
...
}
dependencies {
...
// Add the following dependencies
api project(':liveness')
}
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
:
allprojects {
repositories {
...
maven { url 'https://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
:
dependencyResolutionManagement {
...
repositories {
...
maven {
url 'https://public-n3.advai.net/repository/maven-releases/'
}
}
}
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.1.8 and core 4.5. Modify the version number in the link to download the corresponding version.
liveness/build.gradle
has the version that the SDK depends on(Version Record),Update the SDK by modifying the version number.
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
// You can view the list of SDK versions for updating the SDK at this link
// http://public-n3.advai.net/repository/maven-releases/ai/advance/mobile-sdk/android/liveness-detection-rn/maven-metadata.xml
api 'ai.advance.mobile-sdk.android:liveness-detection-rn:2.1.8'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
}
Add LivenessReactPackage
.
In the android/app
directory, find the class that implements ReactApplication
with the default name MainApplication
, add LivenessReactPackage
import ai.advance.liveness.sdk.rn.LivenessReactPackage;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(), new LivenessReactPackage()
);
}
...
}
...
}
Initialize the SDK.
Available values for Market: [Indonesia, India, Philippines, Philippines2, Vietnam, Malaysia, Thailand, BPS, CentralData, Mexico, Singapore, Aksata, Pakistan, Nigeria]
// The last boolean value represents whether you are opening a Global service or not. If so, it is set to true, otherwise it is false.
NativeModules.LivenessModule.initSDKByLicense("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
NativeModules.LivenessModule.setDetectionLevel('NORMAL');
Check license.
The license is obtained by your server calling our openAPI, which is called before starting the live detection
NativeModules.LivenessModule.setLicenseAndCheck("your license",(successCode)=>{
// license check success,you can start liveness detection.
},(errorCode)=>{
// license is not available, expired/wrong format/appId not match
})
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.
// The action array can be configured with any number of actions
// POS_YAW:Shake head
// MOUTH:Open mouth
// BLINK:Blink
NativeModules.LivenessModule.setActionSequence(true,["POS_YAW", "MOUTH", "BLINK"]);
Customize the size of the returned image
// Settable input range: [300,1000], unit: pixels
NativeModules.LivenessModule.setResultPictureSize(600);
Customized action time
Detection time for custom actions, all actions take effect after setting, unit: Millisecond
NativeModules.LivenessModule.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.
NativeModules.LivenessModule.bindUser("your user id")
Turn on occlusion detection
If you want to enable occlusion detection, please call the following method after initializing the SDK to set it
NativeModules.LivenessModule.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 android/app/build.gradle
android {
defaultConfig {
...
resConfigs("in-rID") // For example, only Indonesian is supported
}
}
Start the liveness detection and obtain the test result.
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.
demo codes:
NativeModules.LivenessModule.startLiveness(
(successJsonData)=>{
// This callback indicates Liveness Detection success
},
(failedJsonData)=>{
// This callback indicates that the Liveness Detection failed or the user canceled the detection
}
)
}}
successJsonData:
Key | Type | Explanation |
---|---|---|
livenessId | String | The picture id |
livenessBase64Str | String | The images collected in base64 format |
transactionId | String | Trace the transaction id of this liveness detection log |
isPay | Boolean | Whether this call is charged |
imageSequenceList | String Array | If set to return multiple images, here is the sequence of images |
failedJsonData
Key | Type | Explanation |
---|---|---|
transactionId | String | Trace the transaction id of this liveness detection log,maybe null |
errorMessage | String | Failed message,maybe null |
errorCode | String | Failed code |
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 |