Predefined capture UI
MBCaptureSessionFragment provides the camera preview, face overlay, countdown, progress, live feedback, and capture lifecycle. Use it unless your application needs complete control over the screen layout.
| Integration | Choose it when |
|---|---|
| Predefined UI | You want the shortest integration and Mobai-managed capture controls. |
| Custom UI | Your application must own the view hierarchy and visual design. |
Configure a production session
val options = MBCaptureSessionOptions.Builder()
.automaticCapture(true)
.framesToCollect(3)
.videoCaptureDuration(2_000)
.timeBeforeCapture(1)
.captureConstrains(MBCaptureConstrains.V3)
.imageQualityLevel(MBImageQualityLevel.LEVEL_2)
.debugging(false)
.build()
val style = MBUIOptions.Builder()
.progressBar(true)
.faceStatusLabel(true)
.countdownTimerLabel(true)
.build()
val captureFragment = MBCaptureSessionFragment().apply {
captureSessionOptions = options
this.style = style
sessionId = currentSessionId
captureSessionFragmentListener = this@IdentityActivity
}
Set the options, style, session ID, and listener before adding the fragment. The fragment persists its options and style when Android recreates it.
Add the fragment
if (savedInstanceState == null) {
supportFragmentManager.commit {
add(R.id.capture_container, captureFragment)
setReorderingAllowed(true)
}
}
sessionId is optional. Supply it when your backend flow needs authenticated frame and video session metadata.
Common capture options
| Builder method | Default | Purpose |
|---|---|---|
automaticCapture | true | Starts capture automatically after validation and countdown. |
framesToCollect | 3 | Number of frames sampled from the video interval; accepts 1...10. |
videoCaptureDuration | 1000 | Video duration in milliseconds; accepts 1000...3000. |
timeBeforeCapture | 1 | Countdown duration in seconds; accepts 0...45. |
captureConstrains | V1 | Selects the V1, V2, or V3 validation pipeline. |
imageQualityLevel | LEVEL_3 | Selects V3 lighting strictness. It has no effect on V1 or V2. |
debugging | false | Enables SDK diagnostics and diagnostic UI. |
payloadOptimization | false | Enables biometric payload-size optimization. |
The Android public API uses the spelling MBCaptureConstrains and captureConstrains.
For a new integration, start with V3 and LEVEL_2, then adjust the quality level after testing on your supported devices and environments.
Configure visible UI components
The optional components default to hidden. Configure them independently of debug mode:
| Builder method | Default | Purpose |
|---|---|---|
progressBar | false | Displays capture progress. |
faceStatusLabel | false | Displays geometry and V3 lighting guidance. |
countdownTimerLabel | false | Displays the automatic-capture countdown. |
Do not enable debugging(true) just to show progress or user guidance. Enable the corresponding MBUIOptions.Builder properties so those components remain available in production builds.
Receive capture events
class IdentityActivity : AppCompatActivity(), MBCaptureSessionFragmentListener {
override fun onSuccess(result: MBCaptureSessionResult?) {
result?.let(::upload)
}
override fun onFailure(errorEnum: MBCaptureSessionError) {
showRetry(errorEnum)
}
override fun onStateChanged(stateEnum: MBCaptureState) {
// INITIALIZING, VALIDATING, COUNTDOWN, CAPTURING, PROCESSING, and CAPTURE_FINISHED.
}
}
The predefined UI handles frame-by-frame feedback itself. The listener reports completion, failure, and state changes.