Configuration
The face capture consists of two components:
MIDFaceView: the camera view. It shows the preview, the detection area and the guidance messages.MIDFaceSDK: the face engine. It detects the face, applies liveness and runs the biometric operation.
Initialisation
Initialise the SDK before using any other component, with the application ID, a token issued by your backend and the full server URL:
MIDSDK.initSDK(
applicationId = "YOUR_APPLICATION_ID",
authToken = authToken,
serverUrl = "https://{SERVER-URL}/api/v7",
context = applicationContext,
)
Since version 7.0.2, the SDK no longer appends the API version. serverUrl must contain the complete host and path.
The token is valid for 30 minutes. Request it right before the user reaches the capture screen, so that it remains valid during the operation.
Camera view
MIDFaceView can be used in XML layouts and in Jetpack Compose:
- XML layout
- Jetpack Compose
<com.mobbeel.mobbid.face.ux.MIDFaceView
android:id="@+id/face_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
AndroidView(
factory = { midFaceView },
modifier = Modifier.fillMaxSize(),
)
Call initView once the view has been laid out. The optional callback runs when the view is ready to receive the engine:
midFaceView.post {
midFaceView.initView {
// Build MIDFaceSDK here
}
}
Face engine
Build MIDFaceSDK with MIDFaceSDKBuilder and attach it to the view:
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)
livenessDetectionMode(MIDFaceLivenessDetectionMode.HEAD_PASSIVE_IMAGE)
addLivenessListener(midFaceView)
}.build()
} catch (e: IllegalStateException) {
// Incomplete configuration or missing permission: e.message describes the cause
}
| Option | Description |
|---|---|
interactiveMode() | Real-time capture from the camera, with user guidance. |
defaultCameraMode | Camera to open. Use MIDFaceCameraMode.FRONT for selfie capture. |
targetView | Container of the camera preview inside MIDFaceView. |
setDetectionBox | Area in which the user must place the face, drawn by MIDFaceView. |
addFeedbackListener | Receives the guidance events (distance, position, lighting). Pass MIDFaceView to display them. |
livenessDetectionMode | Liveness method applied to the capture. See Liveness. |
addLivenessListener | Receives the progress of the liveness check. Pass MIDFaceView to display it. |
build() throws IllegalStateException, or Exception, when the configuration is incomplete or a required permission has not been granted. The exception message describes the cause.
Liveness
Liveness is configured once in the engine and applies to every operation it runs. Use HEAD_PASSIVE_IMAGE: passive liveness on a single image, with no gestures from the user. It detects printed photos, screens and masks presented to the camera.
Keep liveness enabled in every operation, including enrolment. Without it, a photo of another person could be enrolled or verified. See Attack detection.
User guidance and localisation
MIDFaceView guides the user in real time to place the face inside the detection area, at the right distance and with suitable lighting. Its default dialogs are available in English, Spanish and French, and follow the device language.
Lifecycle
faceSDK.start(recognitionMode, parameters, operationListener) // start an operation
faceSDK.stop() // cancel the capture in progress
faceSDK.release() // free the native resources
| Method | When to call it |
|---|---|
start | To run an enrolment, a verification or an identification. |
stop | When the user leaves the capture or you need to cancel it. |
release | In onDestroy of the activity or fragment that hosts the capture. Available since 7.2.1. |
override fun onDestroy() {
super.onDestroy()
faceSDK.release()
}
Runtime permissions
Request the runtime permissions before building the engine:
val permissions: List<String> = MIDFaceSDK.getRequiredPermissions()