Document Capture
DicioCameraDocument Composable component into their Android applications using Jetpack Compose.Compatibilidad y Requisitos
1. Project Setup
Configure your project dependencies by adding the library to your Gradle files and version catalog.
libs.versions.toml
[versions]
dicioDocument = "2.2.0"
[libraries]
dicio-documentcapturesdk = { group = "io.bitbucket.juarezsdco", name = "documentcapturesdk", version.ref = "dicioDocument" }
build.gradle
dependencies {
implementation(libs.dicio.documentcapturesdk)
}
2. Integration and Usage
The SDK is integrated as a @Composable component. Simply call the DicioCameraDocument function within your Compose hierarchy. The component will internally handle the loading and validation of the license before displaying the camera.
Composable.kt
@Composable
fun DicioCameraDocument(
styledScreen: dicioDocumentStyled = dicioDocumentStyled(),
callback: DicioCaptureCallback,
applicationID: String,
token: String,
urlBase: String
)
Composable Parameters
styledScreen: (Optional) AdicioDocumentStyledobject to customize the appearance of the screen.callback: Implementation ofDicioCaptureCallbackto handle SDK events.applicationID: (Required) The application ID provided for license validation.token: (Required) The authentication token (Bearer Token) to authorize requests.urlBase: (Required) The base URL of the server where the token and license will be validated.
Customization (Programmatic)
Interface customization is done by providing a dicioDocumentStyled configuration object to the component.
dicioDocumentStyled Class
| Property | Type | Description | Default Value |
|---|---|---|---|
title | Int (StringRes) | Text resource ID for the title. | R.string.dicio_dc_title |
subtitle | Int (StringRes) | Text resource ID for the subtitle. | R.string.dicio_dc_subtitle |
backgroundColor | Color | Background color of the capture screen. | Color(0xFF000000) (Black) |
titleColor | Color | Text color of the title. | Color.White |
subtitleColor | Color | Text color of the subtitle. | Color.White |
buttonCaptureColor | Color | Color of the capture button. | Color.White |
buttonCancelColor | Color | Color of the close/cancel icon. | Color.White |
Callback Implementation
You must implement the DicioCaptureCallback interface to receive SDK responses and events.
| Method | Description | Parameters |
|---|---|---|
DicioCaptureOnSuccess | Invoked when image capture is successful. | image: Captured image in String format (Base64). |
DicioCaptureOnFailure | Invoked when there is an error during the process. | errorMessage: Error message in String format (JSON). |
DicioCaptureOnCancel | Invoked when the user cancels the capture. | cancelMessage: Message explaining why it was canceled. |
DicioCaptureOnInfoCamera | Provides information about the camera status. | message: Information message in String format (JSON). |
3. Complete Usage Example
The following example shows how to integrate DicioCameraDocument, pass validation parameters, and handle the result.
DocumentCaptureScreen.kt
@Composable
fun DocumentCaptureScreen(
appId: String,
userToken: String,
apiBaseUrl: String
) {
var capturedImageBase64 by remember { mutableStateOf<String?>(null) }
if (capturedImageBase64 == null) {
DicioCameraDocument(
applicationID = appId,
token = userToken,
urlBase = apiBaseUrl,
callback = object : DicioCaptureCallback {
override fun DicioCaptureOnSuccess(image: String) {
capturedImageBase64 = image
}
override fun DicioCaptureOnFailure(errorMessage: String) {
println("Capture error: " + errorMessage)
}
override fun DicioCaptureOnCancel(cancelMessage: String) {
println("Capture canceled: " + cancelMessage)
}
override fun DicioCaptureOnInfoCamera(message: String) {
println("Camera Info: " + message)
}
}
)
} else {
CapturedPhotoResult(
base64Image = capturedImageBase64,
onRetake = { capturedImageBase64 = null }
)
}
}
Error Handling and Response Codes
Messages are delivered as a JSON formatted string with the keys "Code" and "Message".
License and Connectivity Errors
These errors occur before the camera is displayed. The SDK will show an on-screen message and also notify via DicioCaptureOnFailure.
| Error code | Description |
|---|---|
NO_INTERNET | No internet connection available to validate the license. |
APPLICATION_ID_EMPTY | The applicationID parameter is empty. |
BASE_URL_EMPTY | The urlBase parameter is empty. |
TOKEN_EMPTY | The token parameter is empty. |
TOKEN_NOT_VALID | The provided token is invalid or has expired. |
SERVER_ERROR_NOT_LICENCE | The server response did not contain a valid license. |
JSON_PARSE_ERROR | Error processing the server response. |
SERVER_ERROR | General communication error with the license server. |
Camera Errors
| Error code | Description |
|---|---|
ERROR_PERMISSION | Camera permission denied by the user. |
ERROR_CAMERA | General error when starting or binding the camera. |
ERROR_TAKING_PHOTO | Error during photo capture (returned by CameraX). |
ERROR_IMAGE_FORMAT | The camera image format is not JPEG. |
Camera Information Messages
| Information code | Description |
|---|---|
CAMERA_STARTED | The camera started successfully and is ready to capture. |
CAMERA_TAKE_PHOTO | The photo has been taken and is being processed. |