Skip to main content
MÓDULO NATIVO

Document Capture

This documentation provides a detailed guide for developers on how to integrate and implement the DicioCameraDocument Composable component into their Android applications using Jetpack Compose.
Regresar
ANDROIDJETPACK COMPOSEv2.2.0

Compatibilidad y Requisitos

Lenguaje
Kotlin / Java
OS Min
Android 7+
API / Target
API 24+
IDE
Jellyfish+

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) A dicioDocumentStyled object to customize the appearance of the screen.
  • callback: Implementation of DicioCaptureCallback to 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

PropertyTypeDescriptionDefault Value
titleInt (StringRes)Text resource ID for the title.R.string.dicio_dc_title
subtitleInt (StringRes)Text resource ID for the subtitle.R.string.dicio_dc_subtitle
backgroundColorColorBackground color of the capture screen.Color(0xFF000000) (Black)
titleColorColorText color of the title.Color.White
subtitleColorColorText color of the subtitle.Color.White
buttonCaptureColorColorColor of the capture button.Color.White
buttonCancelColorColor Color of the close/cancel icon.Color.White

Callback Implementation​

You must implement the DicioCaptureCallback interface to receive SDK responses and events.

MethodDescriptionParameters
DicioCaptureOnSuccessInvoked when image capture is successful.image: Captured image in String format (Base64).
DicioCaptureOnFailureInvoked when there is an error during the process.errorMessage: Error message in String format (JSON).
DicioCaptureOnCancelInvoked when the user cancels the capture.cancelMessage: Message explaining why it was canceled.
DicioCaptureOnInfoCameraProvides 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 codeDescription
NO_INTERNETNo internet connection available to validate the license.
APPLICATION_ID_EMPTYThe applicationID parameter is empty.
BASE_URL_EMPTYThe urlBase parameter is empty.
TOKEN_EMPTYThe token parameter is empty.
TOKEN_NOT_VALIDThe provided token is invalid or has expired.
SERVER_ERROR_NOT_LICENCEThe server response did not contain a valid license.
JSON_PARSE_ERRORError processing the server response.
SERVER_ERRORGeneral communication error with the license server.

Camera Errors

Error codeDescription
ERROR_PERMISSIONCamera permission denied by the user.
ERROR_CAMERAGeneral error when starting or binding the camera.
ERROR_TAKING_PHOTOError during photo capture (returned by CameraX).
ERROR_IMAGE_FORMATThe camera image format is not JPEG.

Camera Information Messages

Information codeDescription
CAMERA_STARTEDThe camera started successfully and is ready to capture.
CAMERA_TAKE_PHOTOThe photo has been taken and is being processed.