Android Integration
This guide will help you integrate the Facial Lite SDK into your Android application.
You can find sample project containing complete integration of SDK here.
Please follow these steps to integrate this framework.
Integration Guide
- Add Face Recognition SDK to your app by updating your
app/build.gradle
plugins {
id 'com.android.application'
}
android {
...
compileSdk 34
defaultConfig {
...
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
repositories() {
maven {
url "s3://" + S3_BUCKET_ID
credentials(AwsCredentials) {
accessKey S3_ACCESS_KEY
secretKey S3_SECRET_KEY
}
}
}
}
dependencies {
...
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.fetchsky.facialrecognitionlitesdk:sdk:<version-code>'
...
}
Note: S3 Credentials will be provided separately
- In order to initialize SDK instance from your activity, use following code sample
blurThresholdcan be between 50 & 400 and defaults to 100. It is used to validate if the captured frame is blurred or shaky. Applicable with version>=2.0.0.
private void initializeSdk(String base64ImageString) {
Intent intent = new Intent(this, com.fetchsky.facialrecognitionlitesdk.MainActivity.class);
intent.putExtra("facialImage", base64ImageString);
intent.putExtra("blurThreshold", blurThreshold) // Optional: Pass a threshold value
startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeSdk("<Base64ImageString>");
IntentFilter filter = new IntentFilter();
filter.addAction("com.identity.ACTION_SEND_DATA");
registerReceiver(dataReceiver, filter, Context.RECEIVER_EXPORTED);
}
private final BroadcastReceiver dataReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("message", Objects.requireNonNull(intent.getAction()));
if ("com.identity.ACTION_SEND_DATA".equals(intent.getAction())) {
String type = intent.getStringExtra("type");
Bundle payload = intent.getBundleExtra("payload");
if (type != null && payload != null) {
... handle broadcast message here
}
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
// Unregister the BroadcastReceiver when not needed
unregisterReceiver(dataReceiver);
}
Received Message Type
Received message has the following keys in it. type and payload
-
type: "faceRecognition", payload:
{ similarity: float; image: string<base64> } -
type: "error", payload:
{ code: "no_source" | "model_initialization_failed" | "no_face" | "face_detection_failed" | "permission_denied" | "exception"; message: string; }
Example Response
{
"type": "faceRecognition",
"payload": {
"similarity": 0.653,
"image": <base64 image string>
}
}
Theming
To customize the SDK colors, you can define the following color values in your colors.xml file and update them as needed:
<color name="facial_black">#FF000000</color>
<color name="facial_white">#FFFFFFFF</color>
<color name="facial_background">#FFFFFFFF</color>
<color name="facial_accent">#0283CA</color>