Android quick start
This guide gets a working biometric capture on screen with the Mobai-provided fragment. The example uses V3 constraints, shows production feedback, and returns a video with three sampled frames by default.
Requirements
- Android 5.0 (API level 21) or later
- A physical device for production-quality camera testing
1. Install the SDK
Version 2.3.3 is available as bio.mobai:biometric:2.3.3 in Mobai's private Cloudsmith Maven repository. Follow Install with Gradle to store your read-only access token, configure the repository in settings.gradle.kts, and add the dependency to your app module. If your Android build uses Maven, follow Install with Maven instead.
2. Add camera permission
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.CAMERA" />
Request the runtime camera permission before attaching the capture fragment.
3. Add a fragment container
<androidx.fragment.app.FragmentContainerView
android:id="@+id/capture_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
4. Start capture
class IdentityActivity : AppCompatActivity(), MBCaptureSessionFragmentListener {
private val requestCameraPermission = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { granted ->
if (granted) showBiometricCapture()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.identity_activity)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) ==
PackageManager.PERMISSION_GRANTED
) {
showBiometricCapture()
} else {
requestCameraPermission.launch(Manifest.permission.CAMERA)
}
}
@SuppressLint("UnsafeOptInUsageError")
private fun showBiometricCapture() {
val options = MBCaptureSessionOptions.Builder()
.framesToCollect(3)
.videoCaptureDuration(2_000)
.captureConstrains(MBCaptureConstrains.V3)
.imageQualityLevel(MBImageQualityLevel.LEVEL_2)
.build()
val style = MBUIOptions.Builder()
.progressBar(true)
.faceStatusLabel(true)
.countdownTimerLabel(true)
.build()
val captureFragment = MBCaptureSessionFragment().apply {
captureSessionOptions = options
this.style = style
captureSessionFragmentListener = this@IdentityActivity
}
supportFragmentManager.commit {
replace(R.id.capture_container, captureFragment)
setReorderingAllowed(true)
}
}
override fun onSuccess(result: MBCaptureSessionResult?) {
result ?: return
val video = result.capturedVideoData
val frames = result.frames
val faceImage = result.faceImage
// Continue with your upload or verification flow.
}
override fun onFailure(errorEnum: MBCaptureSessionError) {
// Show an error and let the user retry.
}
override fun onStateChanged(stateEnum: MBCaptureState) { }
}
debugging(false) can remain disabled. progressBar(true) and faceStatusLabel(true) make progress and live V3 guidance visible in production.
5. Test the capture
Run the application on a physical Android phone, grant camera access, and keep one face inside the overlay. V3 requires valid face distance, position, pose, and lighting before capture starts.