Document Scan
The Docutain Document Scanner SDK for Android comes with integrated, ready to use UI components for the document scan process. Colors and icons can be changed to match your branding.
Initialization
Make sure you have defined the following package dependencies in your app's build.gradle
file:
def docutainSdkVersion = '1.5.1.8'
//For Document Scanner components
implementation("de.docutain:Docutain-SDK-UI:$docutainSdkVersion")
Initialize the Docutain Android Scanner SDK as described here.
Camera Permission
Declare permissions to use the camera in your AndroidManifest.xml
:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
Runtime permission for camera is handled automatically by the Docutain SDK.
Start Scan
To start the scan process you only have to launch an ActivityResultLauncher
with our predefined ScanResult
contract and wait for it to return.
- Kotlin
- Java
import de.docutain.sdk.ui.ScanResult
val documentScanResult = registerForActivityResult(ScanResult()) { result ->
if(result){
//user finished scan process, continue with your workflow
//generate PDF by using Document.writePDF()
//get detected Text by using DocumentDataReader.getText()
//get data by using DocumentDataReader.analyze()
} else{
//user canceled scan process
}
}
myButton.setOnClickListener {
val scanConfig = DocumentScannerConfiguration()
documentScanResult.launch(scanConfig)
}
import de.docutain.sdk.ui.ScanResult
private ActivityResultLauncher documentScanResult = registerForActivityResult(new ScanResult(),
new ActivityResultCallback<Boolean>() {
@Override
public void onActivityResult(Boolean result) {
if(result){
//user finished scan process, continue with your workflow
//generate PDF by using Document.writePDF()
//get detected Text by using DocumentDataReader.getText()
//get data by using DocumentDataReader.analyze()
} else{
//user canceled scan process
}
}
});
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DocumentScannerConfiguration scanConfig = new DocumentScannerConfiguration();
documentScanResult.launch(scanConfig);
}
});
An instance of DocumentScannerConfiguration
is required to launch the scan activity. It provides the possibility to change some behaviours to adopt it to your needs.
- Kotlin
- Java
val scanConfig = DocumentScannerConfiguration()
//currently supported configs
scanConfig.allowCaptureModeSetting = true //defaults to false
scanConfig.pageEditConfig.allowPageFilter = true //defaults to true
scanConfig.pageEditConfig.allowPageRotation = true //defaults to true
scanConfig.autoCapture = true //defaults to true
scanConfig.defaultScanFilter = ScanFilter.ILLUSTRATION //defaults to ScanFilter.ILLUSTRATION
DocumentScannerConfiguration scanConfig = new DocumentScannerConfiguration();
//currently supported configs
scanConfig.setAllowCaptureModeSetting(true); //defaults to false
scanConfig.getPageEditConfig().setAllowPageFilter(true); //defaults to true
scanConfig.getPageEditConfig().setAllowPageRotation(true); //defaults to true
scanConfig.setAutoCapture(true); //defaults to true
scanConfig.setDefaultScanFilter(ScanFilter.ILLUSTRATION); //defaults to ScanFilter.ILLUSTRATION
All parameters in DocumentScannerConfiguration
are optional.
Result handling
After the scan process is successfully finished, you can do a bunch of things with the scanned pages: