Skip to content

Face IAD activity

Face IAD Activity is a class created to provide a convenient way to use Face IAD solution with minimal integration work.

Dependencies

Besides standard dependencies for Face IAD library you need to add one more to your application's build gradle file:

// build.gradle
implementation 'androidx.activity:activity:1.2.0'
// build.gradle.kts
implementation("androidx.activity:activity:1.2.0")

Start Face IAD Activity

To start FaceIadActivity you need to register FaceIadActivityContract in your activity as it written below:

import android.os.Bundle
import android.widget.Button
import androidx.activity.ComponentActivity
import net.idrnd.android.idlive.face.detection.local.FaceDetectorOptions
import net.idrnd.android.idlive.face.iad.camera.controller.IadOptions
import net.idrnd.face.iad.capture.activity.FaceIadActivityContract
import net.idrnd.face.iad.capture.activity.FaceIadActivityOptions
import net.idrnd.face.iad.capture.activity.UseCaseActivityResultStatus.Canceled
import net.idrnd.face.iad.capture.activity.UseCaseActivityResultStatus.Error
import net.idrnd.face.iad.capture.activity.UseCaseActivityResultStatus.Ok
import your.application.R

class StartActivity : ComponentActivity(R.layout.activity_start) {

    // Necessary register Face IAD Activity contract to your activity
    private val faceIadActivityContract = registerForActivityResult(FaceIadActivityContract()) { result ->
        // After the activity finishes its work it will be closed and the result will be passed to this callback
        when (result.status) {
            Ok -> {
                // Activity took photo and payload
                val selfie = result.capturedData!!.selfie
                val payload = result.payload!!.content
            }

            Canceled -> {
                // User decided to return on previous activity without taking photo.
                // Photo and payload are not represented in the result
            }

            Error -> {
                // Error happens during activity work
                val error = result.error
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        findViewById<Button>(R.id.startFaceIadActivityButton).setOnClickListener {
            // Set activity options
            val options = FaceIadActivityOptions(
                IadOptions.createIadOptions(IadOptions.PayloadSize.Normal),
                FaceDetectorOptions.createFaceDetectorOptions(true)
            )

            // Start Face IAD Activity
            faceIadActivityContract.launch(options)
        }
    }
}

Oval mask colors

To change the colors used by the oval mask, add these lines to the colors.xml file in the resources directory and replace the color values with your own.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="idrnd_color_oval_mask_success_status">#4c9b7c</color>
    <color name="idrnd_color_oval_mask_warning_status">#fbdc5d</color>
    <color name="idrnd_color_oval_mask_failure_status">#FF0000</color>
</resources>

Localization

Face IAD Activity shows a dialog about necessary permissions to a user. To change title and message of this dialog with your own text you need to add these lines to strings.xml in your resources directory.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="idrnd_permissions_request_title">Permissions request</string>
    <string name="idrnd_permissions_request_message">To take a photo, the app requires access to your camera. After this dialog closes, a permission request will appear. Please grant camera access to continue using this feature.</string>
    <string name="idrnd_permissions_settings_button">Settings</string>
    <string name="idrnd_permissions_request_message_with_settings_option">
        It appears that the app can no longer request Camera permission directly. To enable the camera, please grant permission through your phone’s settings.\n\n
        1. Tap the Settings button below\n
        2. Find and open Permissions tab\n
        3. Enable the Camera permission manually\n\n
        This will allow the app to use the camera for taking photos.
    </string>
</resources>

The same necessary to do with messages about quality checks in case if you want to change them.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="idrnd_evaluation_result_too_many_faces">Please position only your face within the frame</string>
    <string name="idrnd_evaluation_result_face_not_found">Please position your face within the frame</string>
    <string name="idrnd_evaluation_result_face_too_small">Please move closer to the camera</string>
    <string name="idrnd_evaluation_result_face_cropped">Please position your face further from the frame’s borders</string>
    <string name="idrnd_evaluation_result_face_angled">Please turn your face to a frontal position</string>
    <string name="idrnd_evaluation_result_face_occluded">Please uncover your face</string>
    <string name="idrnd_evaluation_result_too_close">Please position your face further from the frame’s borders</string>
    <string name="idrnd_evaluation_result_face_is_not_centered">Please center your face within the frame</string>
</resources>