Getting started with MobbScan
SDK Example
Two example application are included in the SDK (One implemented with Java another one with Kotlin). You can find them under at the root folder of the SDK, under the names of sample
and sample-kotlin
.
The example app simply scans a spanish idendity document and then shows all results on screen.
To use it you just have to import it on your Android Studio as a Gradle project using the default gradle wrapper. Once the import has finished you should be able to build and run the sample in your own device.
Perform document scan
License key
To start using the SDK you need to obtain a license key that is bound to your application.
The license key is generated for your specific application package (specified on your AndroidManifest.xml
) and it should be used to initialize the SDK.
NOTE: Internet connectivity is needed to download the license key the first time the SDK is used (and every time the license expires and has to be renewed).
Initialization
First step is always initializing the API. You need to do this before any other action or the SDK will not work. You need your license key to complete this step.
Warning: Since MobbScan 2.14.0 in Android, the default detection method is DNN. If you want to disable this, use the
setDnnDetection(false)
method in the API.
MobbScanAPI.getInstance().initAPI("YOUR_LICENSE_HERE", this, { licenseResult, validTo ->
// Your code for the listener here...
}
MobbScanAPI.getInstance().initAPI("YOUR_LICENSE_HERE", this, new LicenseStatusListener() {
@Override
public void onLicenseStatusChecked(MobbScanLicenseResult licenseResult, Date validTo) {
// Your code for the listener here...
}
});
Note: Please, review your context, as it could be different from
this
.
Setting up the SDK parameters
Now you can set up the SDK based on your specific needs.
For now we will only see the minimum parameters to get MobbScan working.
MobbScanAPI.getInstance().setBaseUrl("YOUR_SERVER_URL_HERE");
Start process
Once the API is initialized and the SDK is configured as you need it, you have to start a new scan process.
var docType = MobbScanDocumentType.ESP
var opMode = MobbScanOperationMode.SCAN_BOTH_SIDES
MobbScanAPI.getInstance().startScan(docType, opMode) { result, scanId, error ->
// Your code for the listener here...
}
MobbScanDocumentType docType = MobbScanDocumentType.ESP;
MobbScanOperationMode opMode = MobbScanOperationMode.SCAN_BOTH_SIDES;
MobbScanAPI.getInstance().startScan(docType, opMode, new ScanStartListener() {
@Override
public void onScanStarted(MobbScanStartScanResult result, String scanId, MobbScanAPIError error) {
// Your code for the listener here...
}
});
The parameters needed on startScan(...)
method are these:
The first parameter is the document type to be scanned. We have a full list of all the documents supported here.
The second parameter is the operation mode to be performed. This can have the next values:
value description SCAN_BOTH_SIDES
The scan operation will include both sides of the document SCAN_ONLY_BACK
The scan operation will include only the back side of the document SCAN_ONLY_FRONT
The scan operation will include only the front side of the document Warning: When you are going to scan a document with just one side (such as Passport_TD3), you must use the scan operation
SCAN_ONLY_BACK
.The third paramter is the ScanStartListener called when the operation is completed. This listener implements a method that returns 3 values:
value description MobbScanStartScanResult result
returns if the operation was OK or some ERROR occured String scanId
returns the scanId associated with the operation we are going to perform MobbScanAPIError error
returns the error code with some extra information Tip: Be sure of saving the
scanId
string, as you will need it for next API calls and for retrieving evidences after the scan process.Note: This scanId is unique for every scan operation (both sides scans are considered as one scan operation), if you want to perform a scan followed by another scan, you must call the
scanStart(...)
method before each scan or the newer scans will override past ones.
Scan a document side
Each side of the document have to be scanned separately, specifying which side is scanned in each step.
Before seeing the actual code we have to understand the two operations that MobbScan performs:
- Detection: this is the part where the camera opens and looks for a document. Once a document it's detected, it will be returned.
- Scan: in this part we take the previously detected document and extract the information from it.
With that knowledge we can call the scanDocument(...)
method passing two listeners, one for each operation that will be performed.
var docSide = MobbScanDocumentSide.FRONT
MobbScanAPI.getInstance().scanDocument(docSide, "YOUR_SCAN_ID_HERE", { result, resultData, error ->
// Your code for the detection listener here...
}, { result, resultData, error ->
// Your code for the scan listener here...
})
MobbScanDocumentSide docSide = MobbScanDocumentSide.FRONT;
MobbScanAPI.getInstance().scanDocument(docSide, "YOUR_SCAN_ID_HERE", new IDDocumentDetectionListener() {
@Override
public void onIDDocumentDetected(MobbScanDetectionResult result, MobbScanDetectionResultData resultData, MobbScanAPIError error) {
// Your code for the listener here...
}
}, new IDDocumentScanListener() {
@Override
public void onIDDocumentScanned(MobbScanScanResult result, MobbScanScanResultData resultData, MobbScanAPIError error) {
// Your code for the listener here...
}
});
Each listener returns different informations:
IDDocumentDetectionListener
MobbScanDetectionResult: represents the possible results for the detect operation:
value description OK
Operation finished sucessfully ERROR
Something happened during the detection process MobbScanDetectionResultData: object containing the bitmap of the document detected and the side of the document detected.
MobbScanAPIError: object that specifies the error ocurred during the process. Contains the error code and extra information about the error.
IDDocumentScanListener
MobbScanScanResult: represents the possible results for the scan operation:
value description COMPLETED
The scan of this side of the document succeed, and the scan of the document has been completed PENDING_OTHER_SIDE
The scan of this side of the document succeed, but there is still another side to be scanned before having the result ERROR
Something happened during the detection process MobbScanScanResultData: object containing the IDDocument object with all the extracted information and the side of the document scanned.
MobbScanAPIError: object that specifies the error ocurred during the process. Contains the error code and extra information about the error.
When the scanDocument(...)
method is called, a new activity will be created and showed, closing itself when the detection process is finished.