Quick start
This guide takes you from an installed SDK to a complete verification: the user scans both sides of an identity document, takes a selfie with passive liveness, and you receive the result.
| # | Step | Call |
|---|---|---|
| 1 | Initialise | initAPI() |
| 2 | Start a process | startScan() |
| 3 | Scan the document | detectpreviewscanDocument() |
| 4 | Verify the face | validateFace() |
| 5 | Get the result | In your backend |
- The SDK is installed and the camera permission is granted.
- You have a license key for your application ID and the URL of your MobbScan environment.
1. Initialise the SDK
Initialise once, before any other call — for example in your Application class or launcher activity — and set the URL of your MobbScan environment.
- Kotlin
- Java
val mobbScan = MobbScanAPI.getInstance()
mobbScan.initAPI("YOUR_LICENSE_KEY", context) { licenseResult, validTo ->
if (licenseResult != MobbScanLicenseResult.LICENSE_VALID) {
// The license is invalid or expired: do not continue
}
}
mobbScan.setBaseUrl("YOUR_MOBBSCAN_URL")
MobbScanAPI mobbScan = MobbScanAPI.getInstance();
mobbScan.initAPI("YOUR_LICENSE_KEY", context, new LicenseStatusListener() {
@Override
public void onLicenseStatusChecked(MobbScanLicenseResult licenseResult, Date validTo) {
if (licenseResult != MobbScanLicenseResult.LICENSE_VALID) {
// The license is invalid or expired: do not continue
}
}
});
mobbScan.setBaseUrl("YOUR_MOBBSCAN_URL");
To change capture behaviour (quality checks, navigation, orientation…), pass a MobbScanConfiguration as a fourth argument. See Configuration.
2. Start a verification process
Each verification is a process identified by a scanId. Start one with the document type and the sides to scan:
- Kotlin
- Java
mobbScan.startScan(MobbScanDocumentType.ESP, MobbScanOperationMode.SCAN_BOTH_SIDES) { result, scanId, error ->
if (result == MobbScanStartScanResult.OK) {
this.scanId = scanId // keep it: every next call needs it
}
}
mobbScan.startScan(MobbScanDocumentType.ESP, MobbScanOperationMode.SCAN_BOTH_SIDES, new ScanStartListener() {
@Override
public void onScanStarted(MobbScanStartScanResult result, String scanId, MobbScanAPIError error) {
if (result == MobbScanStartScanResult.OK) {
MainActivity.this.scanId = scanId; // keep it: every next call needs it
}
}
});
| Operation mode | Use it for |
|---|---|
SCAN_BOTH_SIDES | ID cards, residence permits and other two-sided documents |
SCAN_ONLY_BACK | One-sided documents such as passports (TD3) |
SCAN_ONLY_FRONT | Documents where only the front is required |
This example uses a two-sided identity document. For a one-sided document or passport, see Document scan.
Call startScan again for every new verification. Reusing a scanId overwrites the previous evidence.
3. Scan the document
For a two-sided document, detect each side first and let the user review its preview. The SDK closes its camera screen after detection; your app presents the returned image and lets the user accept it or repeat that side. Send both accepted images in one scanDocument call.
In online mode, the default detectDocument overload can also start MRZ processing automatically when it detects an MRZ document.
- Kotlin
- Java
private fun captureSide(side: MobbScanDocumentSide, onAccepted: (Bitmap) -> Unit) {
mobbScan.detectDocument(
side
) { result, detectionData, error ->
if (result != MobbScanDetectionResult.OK || detectionData == null) {
handleError(error)
return@detectDocument
}
// App-defined preview UI: accept the image or retry this same side.
showPreview(detectionData.image) { accepted ->
if (accepted) onAccepted(detectionData.image)
else captureSide(side, onAccepted)
}
}
}
captureSide(MobbScanDocumentSide.FRONT) { frontImage ->
captureSide(MobbScanDocumentSide.BACK) { backImage ->
mobbScan.scanDocument(scanId, frontImage, backImage) { result, scanData, error ->
if (result == MobbScanScanResult.COMPLETED) verifyFace()
else handleError(error)
}
}
}
interface CaptureAcceptedListener {
void onAccepted(Bitmap image);
}
private void captureSide(MobbScanDocumentSide side, CaptureAcceptedListener onAccepted) {
mobbScan.detectDocument(side,
new IDDocumentDetectionListener() {
@Override
public void onIDDocumentDetected(MobbScanDetectionResult result,
MobbScanDetectionResultData detectionData, MobbScanAPIError error) {
if (result != MobbScanDetectionResult.OK || detectionData == null) {
handleError(error);
return;
}
// App-defined preview UI: accept the image or retry this same side.
showPreview(detectionData.getImage(), accepted -> {
if (accepted) onAccepted.onAccepted(detectionData.getImage());
else captureSide(side, onAccepted);
});
}
});
}
captureSide(MobbScanDocumentSide.FRONT, frontImage ->
captureSide(MobbScanDocumentSide.BACK, backImage ->
mobbScan.scanDocument(scanId, frontImage, backImage, (result, scanData, error) -> {
if (result == MobbScanScanResult.COMPLETED) verifyFace();
else handleError(error);
})
)
);
Implement showPreview with your app's UI. Retry by calling detectDocument for the same side again; do not call scanDocument until the user accepts every required side.
4. Verify the face
Capture a selfie video with passive liveness and match it against the document portrait:
- Kotlin
- Java
mobbScan.validateFace(scanId, MobbScanFaceValidationMode.LIVENESS_VIDEO_PASSIVE, { result, faceData, error ->
// Optional: the selfie, as soon as it is captured
}, { state, validationData, error ->
if (state == MobbScanValidationState.VALID) {
// Liveness and face match passed
}
})
mobbScan.validateFace(scanId, MobbScanFaceValidationMode.LIVENESS_VIDEO_PASSIVE, new FaceAcquisitorListener() {
@Override
public void onFaceAcquired(MobbScanFaceAcquisitorResult result, MobbScanFaceAcquisitorData faceData, MobbScanAPIError error) {
// Optional: the selfie, as soon as it is captured
}
}, new ValidationCheckListener() {
@Override
public void onValidationChecked(MobbScanValidationState state, MobbScanValidationResultData validationData, MobbScanAPIError error) {
if (state == MobbScanValidationState.VALID) {
// Liveness and face match passed
}
}
});
5. Get the result in your backend
The callbacks are meant to drive your UI. Take the final decision in your backend, where the result cannot be tampered with: send the scanId to your server and query the process with the MobbScan Server API, or receive it through a webhook.
See Verification result for the options.