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.
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.
| Operation | What happens | Callback |
|---|---|---|
| Detection | The camera opens, finds the document, checks capture quality and crops it | IDDocumentDetectionListener |
| Scan | Once per document. The captured images are sent together to the server, which classifies the document, extracts the data and runs the validations | IDDocumentScanListener |
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.
- Kotlin
- Java
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()
}
}
}
interface CaptureAcceptedListener {
void onAccepted(Bitmap image);
}
private void detectSide(MobbScanDocumentSide side, CaptureAcceptedListener onAccepted) {
MobbScanAPI.getInstance().detectDocument(side,
new IDDocumentDetectionListener() {
@Override
public void onIDDocumentDetected(MobbScanDetectionResult result,
MobbScanDetectionResultData detectionData, MobbScanAPIError error) {
if (result != MobbScanDetectionResult.OK || detectionData == null) {
handleError(error);
return;
}
showPreview(detectionData.getImage(), accepted -> {
if (accepted) onAccepted.onAccepted(detectionData.getImage());
else detectSide(side, onAccepted);
});
}
});
}
private void 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
| Parameter | Description |
|---|---|
MobbScanDetectionResult | OK or ERROR |
MobbScanDetectionResultData | The cropped image (Bitmap) and the detected side |
MobbScanAPIError | Error code and details when the result is ERROR. See Error codes |
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.
- Kotlin
- Java
private fun scanDocument() {
MobbScanAPI.getInstance().scanDocument(scanId, frontImage, backImage) { result, scanData, error ->
// COMPLETED: data extracted and validated
}
}
private void scanDocument() {
MobbScanAPI.getInstance().scanDocument(scanId, frontImage, backImage,
(result, scanData, error) -> {
// COMPLETED: data extracted and validated
});
}
Scan result
MobbScanScanResult | Meaning | Next step |
|---|---|---|
COMPLETED | The document is complete | Continue with face matching |
ERROR | The side could not be processed | Check 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.
- Kotlin
- Java
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()
}
}
}
}
private void captureBackSide() {
MobbScanAPI.getInstance().detectDocument(MobbScanDocumentSide.BACK,
new IDDocumentDetectionListener() {
@Override
public void onIDDocumentDetected(MobbScanDetectionResult result,
MobbScanDetectionResultData detectionData, MobbScanAPIError error) {
if (result != MobbScanDetectionResult.OK || detectionData == null) {
handleError(error);
return;
}
showPreview(detectionData.getImage(), accepted -> {
if (accepted) {
MobbScanAPI.getInstance().scanDocument(MobbScanDocumentSide.BACK, scanId,
detectionData.getImage(), (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.
Related
- Texts — change the texts shown during detection.