Active Liveness Android SDK (Basic Implementation)
This SDK version update will be not supported in June 2022, please move to the latest update on version 0.6.1, and retrieve the SDK file on the changelog page). Please refers to the new documentation.

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 contact our admin. After you get the .arr file, then copy the .arr file to the app/libs.

Add The Dependencies

Add the following dependencies to your build.gradle on app module:
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 Liveness activity with: <activity android:name="nodeflux.sdk.liveness.Liveness"/> to AndroidManifest.xml. CHeck example below:
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

Go to MainActivity code to configure the Android 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
@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
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, 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();
}
});
}
}
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
<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
<resources>
<string name="left_orientation" translatable="false">Tolehkan kepala ke kiri (30°)</string>
<string name="right_orientation" translatable="false">Tolehkan kepala ke kanan (30°)</string>
<string name="left_eye_blink" translatable="false">Kedipkan mata kiri beberapa kali</string>
<string name="right_eye_blink" translatable="false">Kedipkan mata kanan beberapa kali</string>
<string name="finished" translatable="false">Selesai</string>
<string name="repeat_from_start" translatable="false">Ulang dalam 1.5 detik</string>
<string name="eye_blink" translatable="false">Kedipkan kedua mata beberapa kali</string>
<string name="one_hold" translatable="false">Jangan gerakkan kepala dalam 3 detik</string>
<string name="two_hold" translatable="false">Jangan gerakkan kepala dalam 2 detik</string>
<string name="three_hold" translatable="false">Jangan gerakkan kepala dalam 1 detik</string>
<string name="one_hold_reset" translatable="false">Kepala belum stabil/didalam oval ulang dalam 3 detik</string>
<string name="two_hold_reset" translatable="false">Kepala belum stabil/didalam oval ulang dalam 2 detik</string>
<string name="three_hold_reset" translatable="false">Kepala belum stabil/didalam oval ulang dalam 1 detik</string>
<string name="time_out" translatable="false">Waktu habis ulang dari awal</string>
<string name="hold_failed" translatable="false">Kepala belum stabil, proses gagal</string>
<string name="hold_process" translatable="false">Stabilkan kepala dalam oval</string>
<string name="shake_left" translatable="false">Geleng kepala ke kiri</string>
<string name="shake_right" translatable="false">Geleng kepala ke kanan</string>
<string name="nod_up" translatable="false">Tolehkan kepala Ke atas</string>
<string name="nod_down" translatable="false">Tolehkan kepala Ke bawah</string>
<string name="smile" translatable="false">Mulut tersenyum</string>
<string name="not_smile" translatable="false">Mulut tidak tersenyum</string>
<string name="start_hold" translatable="false">Instruksi telah usai pastikan kepala berada dalam area oval</string>
<string name="start" translatable="false">Pastikan kepala berada dalam area oval</string>
</resources>

Error Message List

Error
Message
Wrong access key or secret key
Error with wrong access key or secret key
Failure access key Authentication
Authentication failure
Failed to connect to the internet
Cannot connect to internet... Please check your connection!
Invalid response parse
Parsing error! Please try again later!
Response takes too long
Connection TimeOut! Please check your internet connection
Internal server error from Nodeflux IdentifAI
Server error please try again

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.

Related Documentation