Configure Face module
This section explains how to configure and use the MobbID Face module.
MIDFaceView
to your views or composables
Step 1: Add You will need to use the MIDFaceView
class in your project. This class is used to manage feedback messages during facial detection as well as to serve as the host for the camera surface.
If you are using traditional Android views (XML layout):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mobbeel.mobbid.face.ux.MIDFaceView
android:id="@+id/face_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
If you are using Jetpack Compose:
AndroidView(
factory = { midFaceView },
modifier = Modifier.fillMaxSize(),
)
MIDFaceView
:
Step 2: Configure You must invoke the initView(initListener: (() -> Unit?)?)
method to properly initialize the class. Optionally, you can pass a listener that will be called upon completion of the initialization.
midFaceView.post {
midFaceView.initView{
// TODO: MIDFaceView has been initialized
}
}
MIDFaceSDK
:
Step 3: Configure try {
faceSDK = MIDFaceSDKBuilder().interactiveMode().apply {
defaultCameraMode(MIDFaceCameraMode.FRONT)
targetView(midFaceView.findViewById(com.mobbeel.mobbid.face.ux.R.id.camera_container))
setDetectionBox(midFaceView.detectionBox)
addFeedbackListener(midFaceView)
}.build()
}catch (e: Exception) {
// TODO: Implement comprehensive error handling logic here (logging, reporting, user feedback, etc.).
}
If your use case requires performing a liveness verification, you can configure it at this step:
try {
faceSDK = MIDFaceSDKBuilder().interactiveMode().apply {
defaultCameraMode(MIDFaceCameraMode.FRONT)
targetView(midFaceView.findViewById(com.mobbeel.mobbid.face.ux.R.id.camera_container))
setDetectionBox(midFaceView.detectionBox)
addFeedbackListener(midFaceView)
if (isPerformLivenessEnabled) {
livenessDetectionMode(MIDFaceLivenessDetectionMode.HEAD_PASSIVE_IMAGE)
addLivenessListener(midFaceView)
}
}.build()
}catch (e: Exception) {
// TODO: Implement comprehensive error handling logic here (logging, reporting, user feedback, etc.).
}
The
MIDFaceSDKBuilder
class may throw exceptions if it is not configured properly or if the necessary permissions are not granted. These exceptions can be of typeException
orIllegalStateException
. Each exception contains a message to report the circumstance that triggered it.
Step 4: Start a face biometric method:
You can now start using the facial biometric method of your choice. You will need to configure a set of parameters and callbacks specific to each method.
faceSDK.start(
recognitionMode = recognitionMode,
parameters = recognitionParameters,
operationListener = callback,
)
You will find more detailed information on how to use the faceSDK.start(...)
method, as well as the parameters associated with each method, in the code examples section.