Android AutoCapture¶
Overview¶
BiometridStandardAutoCapture provides automatic document capture and camera functionality for Android. It supports two capture modes: document capture (using TensorFlow Lite for detection) and face comparison (using ONNX for face detection). The module can operate in auto-capture mode with ML-powered detection or as a simple manual camera.
Prerequisites¶
- BiometridStandardCore must be initialized first
- Android minSdk 24 or higher
- Camera permission granted
Initialization¶
BiometridStandardAutoCapture is accessed through a singleton object. On Android, you must call initialize with a Context before using the module.
import com.biometrid.autocapture.BiometridStandardAutoCapture
import com.biometrid.autocapture.BiometridStandardAutoCaptureCallback
import com.biometrid.autocapture.CaptureOrientation
import com.biometrid.autocapture.model.AutoCaptureModelType
import com.biometrid.autocapture.model.DocumentSide
import com.biometrid.biometridstandard.model.BiometridErrorInfo
import android.graphics.Bitmap
// Initialize with context
BiometridStandardAutoCapture.initialize(context)
Available Methods¶
initialize¶
fun initialize(context: Context)
Initializes the AutoCapture module with the Android application context. Must be called before any other AutoCapture operation.
| Parameter | Type | Description |
|---|---|---|
context |
Context |
Android application context |
set¶
fun set(callback: BiometridStandardAutoCaptureCallback)
Sets the callback to receive capture results.
| Parameter | Type | Description |
|---|---|---|
callback |
BiometridStandardAutoCaptureCallback |
Callback to receive capture results |
configure¶
fun configure(modelType: AutoCaptureModelType)
Configures the ML model type used for auto-capture detection.
| Parameter | Type | Description |
|---|---|---|
modelType |
AutoCaptureModelType |
The detection model to use |
startCapture¶
fun startCapture(side: DocumentSide, orientation: CaptureOrientation = CaptureOrientation.LANDSCAPE)
Starts the auto-capture camera with ML-powered document detection. The camera will automatically capture when a valid document is detected.
| Parameter | Type | Default | Description |
|---|---|---|---|
side |
DocumentSide |
- | Which side of the document to capture (FRONT or BACK) |
orientation |
CaptureOrientation |
LANDSCAPE |
Camera orientation (PORTRAIT or LANDSCAPE) |
startCamera¶
fun startCamera(orientation: CaptureOrientation = CaptureOrientation.LANDSCAPE)
Starts a simple manual camera without auto-capture detection. The user manually triggers the capture.
| Parameter | Type | Default | Description |
|---|---|---|---|
orientation |
CaptureOrientation |
LANDSCAPE |
Camera orientation (PORTRAIT or LANDSCAPE) |
stopCapture¶
fun stopCapture()
Stops the current capture session and closes the camera activity.
setStrings¶
fun setStrings(strings: AutoCaptureStrings)
Sets custom localized strings for the capture UI.
| Parameter | Type | Description |
|---|---|---|
strings |
AutoCaptureStrings |
Custom strings for the capture screens |
Callback Interface¶
BiometridStandardAutoCaptureCallback¶
interface BiometridStandardAutoCaptureCallback {
fun capturedWithSuccess(result: PlatformImage?)
fun capturedWithError(error: BiometridErrorInfo?)
fun captureCancelled()
}
On Android, PlatformImage is a type alias for android.graphics.Bitmap.
| Method | Description |
|---|---|
capturedWithSuccess(result) |
Called when a document is successfully captured. Returns a Bitmap of the captured image. |
capturedWithError(error) |
Called when capture fails. |
captureCancelled() |
Called when the user cancels the capture. |
Enums¶
AutoCaptureModelType¶
enum class AutoCaptureModelType {
DOCUMENT_CAPTURE, // TensorFlow Lite model for document detection
FACE_COMPARE // ONNX model for face comparison/detection
}
DocumentSide¶
enum class DocumentSide {
FRONT, // Front side of document
BACK // Back side of document
}
CaptureOrientation¶
enum class CaptureOrientation {
PORTRAIT, // Portrait camera orientation
LANDSCAPE // Landscape camera orientation
}
Data Models¶
BiometridErrorInfo¶
@Serializable
data class BiometridErrorInfo(
val code: String? = null,
val message: String? = null,
val data: JsonElement? = null
)
AutoCaptureStrings¶
data class AutoCaptureStrings(
val camera: CameraStrings = CameraStrings(),
val simpleCamera: SimpleCameraStrings = SimpleCameraStrings(),
val permissions: ACPermissionsStrings = ACPermissionsStrings()
)
data class CameraStrings(
val centerCard: String = "Please center your card within the frame",
val verifying: String = "We are verifying....",
val taskValidated: String = "Card successfully scanned, thank you!"
)
data class SimpleCameraStrings(
val centerCard: String = "Please center your card within the frame",
val validateOrRetry: String = "Please validate the picture or try again"
)
data class ACPermissionsStrings(
val cameraRequired: String = "Camera Permission Required",
val cameraNeeded: String = "Camera permission is needed to capture photos. Please grant access to continue.",
val grantPermission: String = "Grant Permission",
val cancel: String = "Cancel",
val permissionDenied: String = "Permission Denied",
val permanentlyDenied: String = "Camera permission was permanently denied. Please go to app settings and enable the camera permission to use this feature.",
val openSettings: String = "Open Settings"
)
Error Codes¶
AutoCapture errors use the prefix MSA. Common error codes:
| Code | Description |
|---|---|
MSABACSC001 |
SDK not initialized (startCapture called before initialize) |
MSABACSA001 |
SDK not initialized (context not set) |
MSABSCA001 |
Inference error during ML detection |
MSABSCA002 |
Camera cancelled by user |
MSABSCA003 |
Camera permission denied |
Error Handling¶
Errors are returned as BiometridErrorInfo objects through the capturedWithError callback. All error codes are prefixed with MSA (AutoCapture module).
Usage Example¶
class DocumentCaptureActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Step 1: Initialize the module
BiometridStandardAutoCapture.initialize(this)
// Step 2: Set the callback
BiometridStandardAutoCapture.set(object : BiometridStandardAutoCaptureCallback {
override fun capturedWithSuccess(result: Bitmap?) {
result?.let { bitmap ->
// Process the captured document image
// Convert to base64 or upload to server
}
}
override fun capturedWithError(error: BiometridErrorInfo?) {
Log.e("AutoCapture", "Capture failed: ${error?.message}")
}
override fun captureCancelled() {
Log.d("AutoCapture", "Capture cancelled by user")
}
})
// Step 3: Configure the model type
BiometridStandardAutoCapture.configure(AutoCaptureModelType.DOCUMENT_CAPTURE)
// Step 4: Start auto-capture for front of document
BiometridStandardAutoCapture.startCapture(DocumentSide.FRONT, CaptureOrientation.LANDSCAPE)
}
// To capture back side later:
private fun captureBackSide() {
BiometridStandardAutoCapture.startCapture(DocumentSide.BACK, CaptureOrientation.LANDSCAPE)
}
// To use simple manual camera in portrait:
private fun useManualCamera() {
BiometridStandardAutoCapture.startCamera(CaptureOrientation.PORTRAIT)
}
// To customize UI strings:
private fun customizeStrings() {
BiometridStandardAutoCapture.setStrings(
AutoCaptureStrings(
camera = CameraStrings(
centerCard = "Centre o seu cartão na moldura",
verifying = "A verificar...",
taskValidated = "Cartão digitalizado com sucesso!"
)
)
)
}
override fun onDestroy() {
super.onDestroy()
BiometridStandardAutoCapture.stopCapture()
}
}