Document Capture
This module provides a way to clip and upload the generic documents such as proof of address, adhering to the desired document type, count, and screen configuration. Document type specifies the type of the document to be loaded and the document builder specifies the display configurations such as colors, text, and how many documents will be taken from camera.
Flow overviewFlowchart of this module's usage within the SDK flow. Expand to view it, click the chart to enlarge.
- Configure (no dynamic feature is needed), set the event listener with
AmaniEvent().setListener(...), and start the session. - D1: start the Document module; show the returned fragment.
- D2: upload the document; its verdict arrives later in
stepsResult. - D3: If the upload fails or the step is REJECTED, do not call
upload()again: the data is cleared after it. Open the document capture again (a new fragment, or the old one with your own fragment handling, e.g.popBackStack), capture, then upload, up to your own max attempt.
Starting the capture
To capture a document from camera and let the user crop it use the start()
method of this module.
User Interface Settings
Add the imports below:
import ai.amani.sdk.modules.document.DocBuilder
Then build the DocBuilder UI configuration as shown below:
// Preparing DocumentBuilder for User Interface && Some Logic Operations
val docBuilder = DocBuilder(
tryAgainText = "Tekrar Dene", // Text label
confirmText = "Onayla", // Text label
tryAgainTextColor = R.color.color_blue, // Text color
confirmTextColor = R.color.color_blue, // Text color
captureButtonColor = R.color.white, // Button color
documentCount = 2
) // Indicates the number of documents.
Navigate the Fragment
Captured document files are saved to the device storage in JPG format. Make sure your implementation handles .jpg files when accessing, processing the saved documents.
Add the imports below:
import ai.amani.sdk.Amani
import ai.amani.sdk.interfaces.IUploadCallBack
import ai.amani.sdk.modules.document.interfaces.IDocumentCallBack
Then start the document capture flow and upload the cropped document as shown below:
//Calling Generic Document Fragment and Uploading Documents
val docFragment = Amani.sharedInstance().Document()
.start(
docType = "DOC_TYPE",
documentBuilder = docBuilder,
frameLayout = frameLayout ,
callBack = object : IDocumentCallBack{
override fun cb(
listOfDocumentAbsolutePath: ArrayList<String>?,
isSuccess: Boolean
) {
Amani.sharedInstance().Document().upload(
activity = requireActivity(),
docType = "DOC_TYPE",
callBack = object : IUploadCallBack {
override fun cb(isSuccess: Boolean) {
//Document is uploaded successfully
}
}
)
}
}
)
replaceFragmentWithBackStack(R.id.id_frame_layout, docFragment)
Uploading Generic Documents
If you don't want to use the built in crop screen or upload supported file formats directly you can use the methods shown below.
Supported file types are:
- application/pdf
- jpg
- png
- webp
- bmp
Add the imports below:
import ai.amani.sdk.Amani
import ai.amani.sdk.interfaces.IUploadCallBack
import ai.amani.sdk.modules.document.FileWithType
Then upload documents you already hold as files as shown below:
val docData1 = FileWithType(
byteArray = byteArrayOfPdf,
type = "application/pdf"
) // An object data class first param: byteArray, second param: type (file type: jpeg,pdf,png etc.)
val docData2 = FileWithType(
byteArray = byteArrayOfJpeg,
type = "jpeg"
)
val docDataList = arrayListOf(
docData1,
docData2
)
Amani.sharedInstance().Document().upload(
activity = this,
docType = "DOC_TYPE",
data = docDataList,
callBack = object : IUploadCallBack{
override fun cb(isSuccess: Boolean) {
//If isSuccess true document is uploaded successfully
}
})
A true result means different things per backend version. V2: the document reached the server, not that it was approved; verification runs asynchronously on the backend, so the outcome arrives later through the event listener rather than here. V1: the upload response status was OK or PENDING_REVIEW, so true already carries the verdict.
Alternatively, if you need the ID of the uploaded document, pass the uploadCallBack { ... } helper instead of the callback above. Everything else stays the same:
import ai.amani.sdk.interfaces.uploadCallBack
Amani.sharedInstance().Document().upload(
activity = this,
docType = "DOC_TYPE",
data = docDataList,
callBack = uploadCallBack { isSuccess, documentID ->
// isSuccess is true when the document is uploaded
// documentID is the ID of the uploaded document
}
)
Deleting Document Cache Files (Optional usage, NOT Required!)
It provides a way to delete all file that are taken from camera. If you want to call this, you must call this after the upload process is done. Otherwise upload will fail.
Amani.sharedInstance().Document().deleteAllDocumentCaches()