Android-SDK-Liveness Detection(For React Native 2D)

Demo

Install CV-Demo.apk to your phone and log in with the test account.

Integrate the SDK into your project

  1. 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.

  2. Modify the android/settings.gradle file as follows to add a reference to the liveness module

    ...
    include ':app', ':liveness'
  3. 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
  4. 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')
    }
  5. If pulling aar fails, we recommend trying the following

SDK Version Updates

View version update notes

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'
}

Quick Start

  1. Add LivenessReactPackage.

  2. 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);
  3. 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');   
  4. 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
    })
  5. 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"]);
  6. Customize the size of the returned image

    // Settable input range: [300,1000], unit: pixels
    NativeModules.LivenessModule.setResultPictureSize(600);
  7. Customized action time

    Detection time for custom actions, all actions take effect after setting, unit: Millisecond

    NativeModules.LivenessModule.setActionTimeoutMills(10000);
  8. 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")   
  9. 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)
  10. 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..

  11. 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.

  12. 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" />
  13. 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.

  14. Code proguard configuration

    The SDK already has code proguard, no additional configuration is required.

  15. 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 
  16. SDK Compatibility


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