For the complete documentation index, see llms.txt. This page is also available as Markdown.

Starting Liveness Flow

The Liveness flow has three steps:

  1. configure() : give the SDK your credentials, once.

  2. prewarm() : fetch the liveness session while the user is still on the previous screen.

  3. startLiveness() : open the camera and receive the result.

Splitting the work this way lets the network request happen before the user asks for the camera, so the camera opens noticeably faster.

Configure

Create a CafLivenessConfig and pass it to configure(). This only stores the context and configuration. It makes no network request, so it is safe to call early.

MainActivity.kt
val livenessConfig = CafLivenessConfig(
    mobileToken = "<YOUR_MOBILE_TOKEN>",
    stage = CafStage.PROD,
    personId = "<PERSON_ID>",
    showLoading = true,
    enableSecurity = true
)
CafFaceLivenessLite.instance.configure(context, livenessConfig)

CafLivenessConfig Parameters

Parameter
Default
Description

mobileToken

—

Required. The sessionToken your backend requested for this attempt. See Backend Setup.

personId

—

Required. Identifies the user for the liveness process.

stage

PROD

Target environment: PROD, BETA, or DEV.

showLoading

true

Shows loading indicators during processing when true.

enableSecurity

true

When enabled, runs device security validation before and during liveness. See Security Checks.

uiCustomization

null

Visual branding for the liveness screen. See UI Customization.

Pre-warm

Call prewarm() as soon as you know Liveness is coming — when the user reaches the screen before it, or when the "Start" button becomes visible. The SDK creates the Liveness session in the background so startLiveness() does not have to wait for it.

prewarm() takes no parameters, returns immediately and reports nothing — the work continues in the background. It requires configure() to have been called first.

prewarm() is optional. If you skip it, startLiveness() creates the session itself and everything works exactly the same — just without the speed gain.

Start Liveness

Call startLiveness() with a callback to handle the results and events triggered during the Liveness flow.

If a pre-warm is still running when startLiveness() is called, the SDK waits for it rather than starting a second request — so calling prewarm() shortly before is never wasted.

Complete example

Events

Every run delivers its events to the listener passed to startLiveness(), on the main thread. A run always ends with exactly one of Success, Failure, Error or Cancelled.

Event
When it is delivered

Success(signedResponse: String)

The capture completed. Forward the signedResponse to your backend.

Failure(signedResponse: String, type: CafFailureType, description: String)

The capture ran but did not pass. Guide the user with the type and forward the signedResponse to your backend. See Mobile Failures.

Error(type: CafLivenessErrorType, description: String, cause: Throwable)

The run could not start or finish. No signedResponse. See Android Errors.

Cancelled

The user closed the capture screen. Go back to the previous screen without an error message.

Loading / Loaded

The SDK started / stopped waiting. Use them to show or hide your own loading indicator.

Changing the user or credentials

If you call configure() again with a different mobileToken or personId, any pre-warmed session is discarded, since it belongs to the previous user. Call prewarm() again after reconfiguring.

Releasing the SDK

release() cancels the Liveness in progress and discards any pre-warmed session. The configuration from configure() is kept, so you can call prewarm() or startLiveness() again without reconfiguring.

Debugging

To see the SDK logs in Logcat, enable logging. Logs only appear when your app is debuggable; in release builds the flag is ignored.

Next step

Forward the signedResponse to your backend, which validates it and retrieves the result: Backend Setup.

Last updated