Skip to main content

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.

IntegrationChoose it when
Predefined UIYou want the shortest integration and Mobai-managed capture controls.
Custom UIYour 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 methodDefaultPurpose
automaticCapturetrueStarts capture automatically after validation and countdown.
framesToCollect3Number of frames sampled from the video interval; accepts 1...10.
videoCaptureDuration1000Video duration in milliseconds; accepts 1000...3000.
timeBeforeCapture1Countdown duration in seconds; accepts 0...45.
captureConstrainsV1Selects the V1, V2, or V3 validation pipeline.
imageQualityLevelLEVEL_3Selects V3 lighting strictness. It has no effect on V1 or V2.
debuggingfalseEnables SDK diagnostics and diagnostic UI.
payloadOptimizationfalseEnables 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 methodDefaultPurpose
progressBarfalseDisplays capture progress.
faceStatusLabelfalseDisplays geometry and V3 lighting guidance.
countdownTimerLabelfalseDisplays the automatic-capture countdown.
Debug mode

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.

Continue the integration​