Face Liveness Android SDK (Basic Implementation)
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 attacks.
    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 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
1
dependencies {
2
implementation files('libs/liveness.aar')
3
implementation 'androidx.camera:camera-view:1.0.0-alpha15'
4
implementation 'com.google.mlkit:face-detection:16.0.2'
5
implementation 'androidx.camera:camera-camera2:1.0.0-beta08'
6
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.20'
7
implementation 'com.android.volley:volley:1.1.1'
8
}
Copied!
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
1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
package="com.example.myapplication">
4
5
<application
6
android:allowBackup="true"
7
android:icon="@mipmap/ic_launcher"
8
android:label="@string/app_name"
9
android:roundIcon="@mipmap/ic_launcher_round"
10
android:supportsRtl="true"
11
android:theme="@style/Theme.SDKDemo">
12
<activity android:name=".MainActivity">
13
<intent-filter>
14
<action android:name="android.intent.action.MAIN" />
15
16
<category android:name="android.intent.category.LAUNCHER" />
17
</intent-filter>
18
</activity>
19
<activity android:name="nodeflux.sdk.liveness.Liveness" /> ←- this line
20
</application>
21
22
</manifest>
Copied!

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
1
@Override
2
protected void onCreate(Bundle savedInstanceState) {
3
super.onCreate(savedInstanceState);
4
setContentView(R.layout.activity_main);
5
6
intent = new Intent(MainActivity.this, Liveness.class);
7
intent.putExtra("ACCESS_KEY", "{ACCESS_KEY_HERE}");
8
intent.putExtra("SECRET_KEY", "{SECRET_KEY_HERE}");
9
intent.putExtra("THRESHOLD", "{THRESHOLD_HERE}"); <-- require double value 1.0. Default value is 0.7
10
Liveness.setUpListener(new Liveness.LivenessCallback() {
11
@Override
12
public void onSuccess(boolean isLive, Bitmap bitmap, double score) {
13
Toast.makeText(MainActivity.this, String.valueOf(isLive), Toast.LENGTH_LONG).show();
14
}
15
16
@Override
17
public void onError(String message) {
18
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
19
}
20
});
21
}
Copied!
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
1
public class MainActivity extends AppCompatActivity {
2
Intent intent;
3
4
@Override
5
protected void onCreate(Bundle savedInstanceState) {
6
super.onCreate(savedInstanceState);
7
setContentView(R.layout.activity_main);
8
if (!isCameraPermissionGranted()) {
9
requestCameraPermission();
10
} else {
11
intent = new Intent(MainActivity.this, Liveness.class);
12
intent.putExtra("ACCESS_KEY", "");
13
intent.putExtra("SECRET_KEY", "");
14
intent.putExtra("THRESHOLD", "0.5");
15
Liveness.setUpListener(new Liveness.LivenessCallback() {
16
@Override
17
public void onSuccess(boolean isLive, Bitmap bitmap, double score)
18
{
19
Toast.makeText(MainActivity.this, String.valueOf(isLive),
20
21
Toast.LENGTH_LONG).show();
22
23
}
24
25
@Override
26
public void onError(String message) {
27
Toast.makeText(MainActivity.this, message,
28
29
Toast.LENGTH_LONG).show();
30
}
31
});
32
}
33
}
34
35
public void onButtonPressed(View v) {
36
startActivity(intent);
37
}
38
public void requestCameraPermission() {
39
ActivityCompat.requestPermissions(this, new
40
String[]{Manifest.permission.CAMERA}, 101);
41
}
42
public boolean isCameraPermissionGranted() {
43
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
44
if (checkSelfPermission(Manifest.permission.CAMERA) ==
45
46
PackageManager.PERMISSION_GRANTED) {
47
48
Log.v("permission", "Camera Permission is granted");
49
return true;
50
} else {
51
Log.v("permission", "Camera Permission is revoked");
52
return false;
53
}
54
} else {
55
Log.v("permission", "Camera Permission is granted");
56
return true;
57
}
58
}
59
}
Copied!

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
1
<color name="face_area">#C8000000</color>
2
<color name="instruction_area">#CB2B2B2B</color>
Copied!
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
1
<resources>
2
<string name="left_orientation" translatable="false">Tolehkan kepala ke kiri (30°)</string>
3
<string name="right_orientation" translatable="false">Tolehkan kepala ke kanan (30°)</string>
4
<string name="left_eye_blink" translatable="false">Kedipkan mata kiri beberapa kali</string>
5
<string name="right_eye_blink" translatable="false">Kedipkan mata kanan beberapa kali</string>
6
<string name="finished" translatable="false">Selesai</string>
7
<string name="repeat_from_start" translatable="false">Ulang dalam 1.5 detik</string>
8
<string name="eye_blink" translatable="false">Kedipkan kedua mata beberapa kali</string>
9
<string name="one_hold" translatable="false">Jangan gerakkan kepala dalam 3 detik</string>
10
<string name="two_hold" translatable="false">Jangan gerakkan kepala dalam 2 detik</string>
11
<string name="three_hold" translatable="false">Jangan gerakkan kepala dalam 1 detik</string>
12
<string name="one_hold_reset" translatable="false">Kepala belum stabil/didalam oval ulang dalam 3 detik</string>
13
<string name="two_hold_reset" translatable="false">Kepala belum stabil/didalam oval ulang dalam 2 detik</string>
14
<string name="three_hold_reset" translatable="false">Kepala belum stabil/didalam oval ulang dalam 1 detik</string>
15
<string name="time_out" translatable="false">Waktu habis ulang dari awal</string>
16
<string name="hold_failed" translatable="false">Kepala belum stabil, proses gagal</string>
17
<string name="hold_process" translatable="false">Stabilkan kepala dalam oval</string>
18
<string name="shake_left" translatable="false">Geleng kepala ke kiri</string>
19
<string name="shake_right" translatable="false">Geleng kepala ke kanan</string>
20
<string name="nod_up" translatable="false">Tolehkan kepala Ke atas</string>
21
<string name="nod_down" translatable="false">Tolehkan kepala Ke bawah</string>
22
<string name="smile" translatable="false">Mulut tersenyum</string>
23
<string name="not_smile" translatable="false">Mulut tidak tersenyum</string>
24
<string name="start_hold" translatable="false">Instruksi telah usai pastikan kepala berada dalam area oval</string>
25
<string name="start" translatable="false">Pastikan kepala berada dalam area oval</string>
26
</resources>
Copied!

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

Last modified 4d ago