Liveness Android Native SDK

Learn how to integrate our Liveness Android Native SDK in your application.

This guide will walk you through the steps required to integrate Bureau’s Liveness Android Native SDK into your project.

Prerequisites

Before integrating our Liveness Android Native SDK into your application, you need to obtain your API keys. There are 2 ways to get API keys:

Minimum Requirements

  • Minimum SDK version: 16
  • AndroidX libraries

Additional Dependencies

This library depends on some common Android libraries. Make sure you have the following added to your project if you don't already:

  • androidx.appcompat:appcompat:1.0.0
  • androidx.constraintlayout:constraintlayout:1.1.3
  • com.google.android.material:material:1.0.0

Integration Steps

1. Install the Liveness SDK

  1. Add the Liveness repository to your root build.gradle file.
allprojects {  
    repositories {  
        ...  
        maven { url "<https://gitlab.com/api/v4/projects/24251481/packages/maven>" }  
    }  
}
  1. Add the Liveness library to your module-level build.gradle file
dependencies {  
    ....  
    implementation "co.invoid.android:livenesscheck:1.0.7rc1"
}

2. Initialize the Liveness SDK

Our SDK supports both English and Hindi. By default, it follows the device's system language settings. However, you can override this behavior to force a specific language.

Initialize SDK using Language Behavior

Use the below code to initialize the SDK using the default language behavior.

yourinitbutton.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                LivenessHelper.with(YourActivity.this, "YOUR_AUTH_KEY").start()  
            }  
        });

Force the SDK to Initialize in English

Use the below code to override the default SDK behavior and force the SDK to initialize in English.

yourinitbutton.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                LivenessHelper.with(YourActivity.this, "YOUR_AUTH_KEY",  
LivenessHelper.LANGUAGE_ENGLISH).start();  
            }  
        });

Force the SDK to Initialize in Hindi

Use the below code to override the default SDK behavior and force the SDK to initialize in Hindi.

yourinitbutton.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View v) {  
			LivenessHelper.with(YourActivity.this, "YOUR_AUTH_KEY",  
LivenessHelper.LANGUAGE_HINDI).start();  
            }  
        });

3. Handling the SDK Response

Our SDK returns a LivenessResponse object containing the following data:

  • Selfie image path: Use LivenessResponse.getSelfieFilePath() to retrieve the path to the captured selfie image.
  • Liveness API response: Use LivenessResponse.getLivenessApiResponse() to access the raw response from the Liveness API.

Add the below code to override the onActivityResult method in your activity to handle the results returned by the Liveness SDK.

@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if(requestCode == LivenessHelper.LIVENESS_HELPER_REQ_CODE) {
        
            if(resultCode == Activity.RESULT_OK) {
                LivenessResponse livenessResponse = data.getParcelableExtra(LivenessHelper.RESULT);
                String selfiePath = livenessResponse.getSelfieFilePath();
                LivenessApiResponse livenessApiResponse = livenessApiResponse.getLivenessApiResponse();
                
           } else if(resultCode == LivenessHelper.AUTHORIZATION_RESULT) {
                int authorizationResult = data.getIntExtra(LivenessHelper.AUTHORIZATION_RESULT, -1);
                if(authorizationResult == LivenessHelper.UNAUTHORIZED) {
                    Log.d(TAG, "onActivityResult: unauthorized");
                } else {
                    Log.d(TAG, "onActivityResult: authorization error");
                }
            } else if(resultCode == Activity.RESULT_CANCELED) {
                Log.d(TAG, "onActivityResult: cancelled by user");
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }