Skip to main content

Document scan

The document scan captures each side of the document with automatic detection, extracts its data on the MobbScan server and returns the validation results.

Before you begin

Initialise the SDK and start a process to get a scanId.

How it works​

For a two-sided document, detect each side (retry if rejected), then scan the accepted images together once per document.

OperationWhat happensCallback
DetectionThe camera opens, finds the document, checks capture quality and crops itIDDocumentDetectionListener
ScanOnce per document. The captured images are sent together to the server, which classifies the document, extracts the data and runs the validationsIDDocumentScanListener

Detect and review both sides before scanning. For a one-sided document or passport, use the side-specific scan.

1. Detect each side​

Detect each required side, show the returned image in an app-owned preview, and repeat detection for that side if the user rejects it. Store each accepted image and submit all required images together in the next step. In online mode, detecting an MRZ document can start MRZ processing automatically with the default overload.

private fun detectSide(side: MobbScanDocumentSide, onAccepted: (Bitmap) -> Unit) {
MobbScanAPI.getInstance().detectDocument(
side
) { result, detectionData, error ->
if (result != MobbScanDetectionResult.OK || detectionData == null) {
handleError(error)
return@detectDocument
}

showPreview(detectionData.image) { accepted ->
if (accepted) onAccepted(detectionData.image)
else detectSide(side, onAccepted)
}
}
}

private fun captureDocument() {
detectSide(MobbScanDocumentSide.FRONT) { frontImage ->
this.frontImage = frontImage
detectSide(MobbScanDocumentSide.BACK) { backImage ->
this.backImage = backImage
scanDocument()
}
}
}

Implement showPreview in your app. Accepting an image continues to the next side; rejecting it calls detection again for the same side. The SDK's camera screen closes after each detection.

Detection result​

ParameterDescription
MobbScanDetectionResultOK or ERROR
MobbScanDetectionResultDataThe cropped image (Bitmap) and the detected side
MobbScanAPIErrorError code and details when the result is ERROR. See Error codes
Images

The image returned by detection arrives in the detection callback. Store it there if you need it.

2. Scan the captured images​

Once every required side has been captured and accepted, submit the accepted images in one scanDocument call.

private fun scanDocument() {
MobbScanAPI.getInstance().scanDocument(scanId, frontImage, backImage) { result, scanData, error ->
// COMPLETED: data extracted and validated
}
}

Scan result​

MobbScanScanResultMeaningNext step
COMPLETEDThe document is completeContinue with face matching
ERRORThe side could not be processedCheck the MobbScanAPIError

With SCAN_ONLY_BACK or SCAN_ONLY_FRONT, scanning the required side returns COMPLETED.

MobbScanScanResultData contains the scanned side and an IDDocument with the extracted fields (name, surname, document number, dates, nationality, MRZ…) and the result of each validation. The full list of fields and validations is described in the document object.

One-sided documents and passports​

For a passport (TD3) or another document that requires only the back, start the process with SCAN_ONLY_BACK and call captureBackSide(). The example previews the detected image before scanning; rejecting it repeats detection. For a front-only document, use SCAN_ONLY_FRONT and apply the same sequence to MobbScanDocumentSide.FRONT.

private fun captureBackSide() {
MobbScanAPI.getInstance().detectDocument(
MobbScanDocumentSide.BACK
) { result, detectionData, error ->
if (result != MobbScanDetectionResult.OK || detectionData == null) {
handleError(error)
return@detectDocument
}

showPreview(detectionData.image) { accepted ->
if (accepted) {
MobbScanAPI.getInstance().scanDocument(
MobbScanDocumentSide.BACK, scanId, detectionData.image
) { scanResult, scanData, scanError ->
// Process the one required side (for example, a passport)
}
} else {
captureBackSide()
}
}
}
}

Documents with a PDF417 barcode​

Some documents, such as Colombian or Peruvian ID cards, carry a PDF417 barcode with additional data. Add a barcode reading step before the document detection to read it with higher accuracy:

MobbScanAPI.getInstance().configurePDF417DetectionStep(true) // enable, 10 s timeout
MobbScanAPI.getInstance().configurePDF417DetectionStep(true, 20) // enable, custom timeout in seconds

If the barcode cannot be read within the timeout, the flow continues with the regular document detection. This step uses the com.google.zxing:core library, which Gradle resolves automatically when you use the Maven repository. Legacy ZIP/AAR distributions must add it as described in their package.

  • Texts — change the texts shown during detection.