Face Liveness Android SDK (Beta Version)

This SDK provides some sets of activities to check face liveness for the purpose of liveness verification. The SDK gives you some benefits to create better onboarding flow during the verification process, such as:

  • Double spoof checking by performing AI model combination of active liveness process and passive liveness.

  • Carefully designed simple UI to guide your customers to perform motion checking for preventing liveness attack.

  • Secure the spoofing activity by filtering artificial input such as masks, print attacks, and replay attacks.

How the SDK Works

The SDK will verify the face liveness twice, first by checking the motion and then does the passive liveness check. The motion check will be done on the SDK (on the device), but the passive check will be sent to the Nodeflux.

  1. To be verified as “Live”, a person should do liveness instructions.

  2. All of the instructions must be done in under 10 seconds. Otherwise, the process will start from the beginning.

  3. Only a single face in the frame is allowed, otherwise, the process cannot continue and will start from the beginning.

  4. The face-id of the user must be consistent. If there any face changes during the process, the SDK will be detected as a different person, so the process will start from the beginning.

  5. Please frame the face and neck are captured on the guidance frame. Check the pose guideline below:

Pose Guideline: Frame the face and neck on the guidance frame.

Disclaimer

This SDK version is still on the beta stage which is still undergoing final testing before its official release. If you want to get the beta trial, please contact us.

You might encounter any bugs, glitches, lack of functionality, or other problems, please contact us if you find that problem.

Getting Started

Supported API Level

The SDK support API level 21 and above (maximum API level 30).

Get Access Key

Before starting integration, you will need API access_key and secret_key . You can get the access_key and secret_key on your application dashboard, please visit dashboard.identifai.id/application.

Prepare the SDK Library

To get the SDK Library, please download the file on this link sdk_libs, then copy the SDK file to the app/libs.

Add The Dependencies

Add the following dependencies to your build.gradle file:

gradle
gradle
dependencies {
implementation files('libs/liveness.aar')
implementation 'androidx.camera:camera-view:1.0.0-alpha15'
implementation 'com.google.mlkit:face-detection:16.0.2'
implementation 'androidx.camera:camera-camera2:1.0.0-beta08'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.20'
implementation 'com.android.volley:volley:1.1.1'
}

Then sync the changes, so the SDK is ready to be configured.

Set Up the SDK

Configure AndroidManifest.xml

Add the SDK activity nodeflux.sdk.liveness.Liveness to AndroidManifest.xml.

Java
Java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SDKDemo">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="nodeflux.sdk.liveness.Liveness" /> ←- this line
</application>
</manifest>

Configure the Activity

Ensure the activity is granted with camera permission because the Face Liveness SDK needs to capture the face. You need to fill the access_key and secret_key to do that activity. Please check the snippet below:

Java
Java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intent = new Intent(MainActivity.this, Liveness.class);
intent.putExtra("ACCESS_KEY", "{ACCESS_KEY_HERE}");
intent.putExtra("SECRET_KEY", "{SECRET_KEY_HERE}");
intent.putExtra("THRESHOLD", "{THRESHOLD_HERE}"); <-- require double value 1.0. Default value is 0.7
Liveness.setUpListener(new Liveness.LivenessCallback() {
@Override
public void onSuccess(boolean isLive, Bitmap bitmap, double score) {
Toast.makeText(MainActivity.this, String.valueOf(isLive), Toast.LENGTH_LONG).show();
}
@Override
public void onError(String message) {
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
});
}

Where:

  • ACCESS_KEY: a user key for authentication purposes.

  • SECRET_KEY: the private key for authentication purposes.

  • THRESHOLD: the value defined by the user to determine the verification is true or false. The value requires double type, for example 1.0, the Default value is 0.7

  • isLive: boolean type to return face liveness check is true or false.

  • bitmap: return an image with bitmap type.

  • message: return an error message.

  • score : return liveness score on a double type from 0 to 1

To check the result you can use the livenessCallback method onSuccess and onError.

Implementation Example:

Java
Java
public class MainActivity extends AppCompatActivity {
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!isCameraPermissionGranted()) {
requestCameraPermission();
} else {
intent = new Intent(MainActivity.this, Liveness.class);
intent.putExtra("ACCESS_KEY", "");
intent.putExtra("SECRET_KEY", "");
intent.putExtra("THRESHOLD", "0.5");
Liveness.setUpListener(new Liveness.LivenessCallback() {
@Override
public void onSuccess(boolean isLive, Bitmap bitmap) {
Toast.makeText(MainActivity.this, String.valueOf(isLive),
Toast.LENGTH_LONG).show();
}
@Override
public void onError(String message) {
Toast.makeText(MainActivity.this, message,
Toast.LENGTH_LONG).show();
}
});
}
}
public void onButtonPressed(View v) {
startActivity(intent);
}
public void requestCameraPermission() {
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.CAMERA}, 101);
}
public boolean isCameraPermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.CAMERA) ==
PackageManager.PERMISSION_GRANTED) {
Log.v("permission", "Camera Permission is granted");
return true;
} else {
Log.v("permission", "Camera Permission is revoked");
return false;
}
} else {
Log.v("permission", "Camera Permission is granted");
return true;
}
}
}

Customizing SDK Theme

In order to enhance the user experience on your application, you can customize the SDK theme customization, such as change the face guidance area color, text area instruction, and the text instruction itself.

You can provide some customization by defining certain colors on the colors.xml file:

  • face_area: Defines the color of the face area to guide the user to capture the face fit with the guidance.

  • instruction_area: Defines the color of the text area which contains test instruction.

Implementation example:

xml
xml
<color name="face_area">#C8000000</color>
<color name="instruction_area">#CB2B2B2B</color>

To customize the instruction you can provide certain instructions text on the strings.xml file:

  • left_orientation: Defines the instruction for the user to turn the face to the left

  • rigth_orientation: Defines the instruction for the user to turn the face to the right

  • eye_blink: Defines the instruction for the user to blink both of the eyes

  • finished: Defines the information message if the liveness the active liveness is done.

  • repeat_from_start: Define the instruction for the user to repeat the instruction after unsuccess verification on the active liveness after 1.5 seconds.

Implementation example:

xml
xml
<string name="left_orientation" translatable="false">Look over your left shoulder (30°)</string>
<string name="right_orientation" translatable="false">Look over your right shoulder (30°)</string>
<string name="finished" translatable="false">Finished</string>
<string name="repeat_from_start" translatable="false">Repeat from start in 1.5 seconds</string>
<string name="eye_blink" translatable="false">Blink both of your eyes</string>

Sample App and SDK File

To get the sample app, please get it on Google Play Store. To get the beta version of our SDK please contact our admin via contact us.