Unico IDCloud - DevCenter
HomepageAuthenticationAPIsSDKs
English (United States)
English (United States)
  • Welcome
  • GETTING STARTED
    • Unico IDCloud
    • Capabilities
    • Integration Methods
    • Capabilities and Integration Methods
  • INTEGRATIONS
    • Quickstart
    • Authentication
      • Creating a Service Account
      • Preparing to Make an Authenticated API Request
      • Additional Resources
        • Example in Javascript
        • Authentication Errors
        • Postman Collection
    • Integration by Unico
      • Overview
      • API
        • API Reference
          • CreateProcess
            • CreateProcess separated by flows
          • GetProcess
          • GetSelfie
          • GetEvidenceSet
            • Specification of the evidential set
          • GetDocumentSigned
          • GetEvidenceSign
        • Errors
      • Controlling the experience
        • Redirecting the user
        • SDK
        • QR Code
        • Customizations
      • Additional Resources
        • Postman Collection
        • PoCs available
    • Integration by Client
      • Overview
      • API
        • API Reference
          • Liveness + Identity Verification + Behavior Alert
          • Liveness + Identity Verification + Behavior Alert + Risk Score
          • Liveness + Validation (1:1) + Behavior Alert
          • Document Capture and Reuse
        • Response Scenarios
        • Additional Resources
          • Postman Collection
      • Capture standard (without SDK)
    • Webhook
    • SDK
      • Overview
      • Update Policy
      • SDK Integration
        • Android SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
          • Error Handling Guide
          • Android Customization
          • Troubleshooting
          • Release notes
        • iOS SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
          • Error Handling Guide
          • iOS Customization
          • Troubleshooting
          • Release notes
        • Flutter SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
          • Error Handling Guide
          • Flutter Customization
          • Troubleshooting
          • Release notes
        • Web SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
            • Accessibility
          • Error Handling Guide
          • Web Customization
          • Release notes
      • Additional Resources
        • Available PoCs
        • Best Practices for SDK Implementation
  • help & faq
    • Glossary
    • Help Center
Powered by GitBook

Institucional

  • Sobre nós

Copyright © 2024 unico. All rights reserved

On this page
  • Available Document Frames
  • Initializing the SDK
  • Implementing Callback Functions
  • Implementing Listeners for Camera Events
  • Prepare and open the camera
  • onSucessDocument Method
  • onErrorDocument Method
  • Making a POST Request to the Client API

Was this helpful?

Export as PDF
  1. INTEGRATIONS
  2. SDK
  3. SDK Integration
  4. Android SDK
  5. Usage and Integration Guide

Document Capture

In this section, you will find all the necessary information for using and integrating the Unico IDCloud SDK into your Android applications for document capture

PreviousSelfie CaptureNextError Handling Guide

Last updated 2 months ago

Was this helpful?


This guide has been created to help you implement the Android SDK quickly and easily. Below, you will find a step-by-step process for the entire integration. Afterward, if you wish to customize the experience, be sure to check out the section.

Available Document Frames


In this camera mode, there is a capture frame to assist the user in positioning the document correctly. Once the document is correctly positioned, the user must click the button to capture the photo of the document.

The SDK does not perform any type of validation on what is being captured.

In this camera mode, it is possible to capture the following documents:

  • CPF: Capture the front of the CPF;

  • CNH: Capture the open CNH;

  • CNH Front: Capture the front of the CNH;

  • CNH Back: Capture the back of the CNH;

  • RG Front: Capture the front of the RG;

  • RG Back: Capture the back of the RG;

  • Others: Capture any other document.

Initializing the SDK


Create an instance of the builder (generated through the IAcessoBioBuilder interface), providing the relevant context and the implementation of the AcessoBioListener class as parameters.

The implementation of this class is quite simple and can be done with just a few lines of code. All you need to do is instantiate the builder by specifying the context and override the callback methods with the business logic of your application:

public class MainActivity extends AppCompatActivity {

    private AcessoBioListener callback = new AcessoBioListener() {
        @Override
        public void onErrorAcessoBio(ErrorBio errorBio) { }

        @Override
        public void onUserClosedCameraManually() { }

        @Override
        public void onSystemClosedCameraTimeoutSession() { }

        @Override
        public void onSystemChangedTypeCameraTimeoutFaceInference() { }
    };

    private IAcessoBioBuilder acessoBioBuilder = new AcessoBio(this, callback);
}
internal class MainActivity : AppCompatActivity() {

    private val callback = object : AcessoBioListener {
        override fun onErrorAcessoBio(errorBio: ErrorBio?) { }
    
        override fun onUserClosedCameraManually() { }
    
        override fun onSystemClosedCameraTimeoutSession() { }
    
        override fun onSystemChangedTypeCameraTimeoutFaceInference() { }
    }

    private val acessoBioBuilder: IAcessoBioBuilder = AcessoBio(this, callback)
}

Implementing Callback Functions


Note that the work of implementing the AcessoBioListener class is largely about configuring the callback methods. Each method is called in a specific situation based on the SDK's return.

Simply override the methods shown in the previous step with your application's business logic:

1

onErrorAcessoBio(ErrorBio errorBio)

2

onUserClosedCameraManually()

This method is invoked whenever the user manually closes the camera, such as by clicking the "Back" button.

3

onSystemClosedCameraTimeoutSession()

This method is invoked as soon as the maximum session time is reached (without capturing any image).

It can be configured in the builder through the setTimeoutSession method. This method should receive the maximum session time in seconds. You can change the maximum session time for your user when using the face detection feature (Selfie camera with smart capture). If the user exceeds the time set in your process to capture the photo, you can display a customizable message or instruction to the user. The default value is 40 seconds, and the minimum value is also 40 seconds.

4

onSystemChangedTypeCameraTimeoutFaceInference()

This method is invoked as soon as the maximum time for detecting the user's face is reached (without detecting anything). In this case, the camera mode is automatically switched to manual capture mode (without the smart capture outline).

The maximum capture time when using face detection (Selfie camera with smart capture) is 13 seconds. If the user encounters difficulty capturing the photo through face detection and exceeds the time set in the process, the capture is automatically switched to manual mode, aiming to make the action easier for the user (TimeoutToFaceInference).

All the above methods must be created as indicated in your project (even without any logic). Otherwise, the project will not compile successfully.

Implementing Listeners for Camera Events


The implementation of these listener methods must be done through an instance of the iAcessoBioSelfie class.

The camera opening method, which is called in the next step, needs to know what to do when it successfully captures an image or when an error occurs in the process. It is necessary to inform "what to do" to the camera opening method by implementing listeners that are called in cases of success or error.

Through the configuration of the listeners, you can specify what happens in your app in error situations (onErrorDocument method) or success situations (onSuccessDocument method) during image capture.

The example below illustrates the configuration of the listeners, building, and opening of the camera:

iAcessoBioDocument cameraListener = new iAcessoBioDocument() {
    @Override
    public void onSuccessDocument(ResultCamera result) { }

    @Override
    public void onErrorDocument(ErrorBio errorBio) { }
};

unicoCheckCamera.prepareDocumentCamera(unicoConfig, new DocumentCameraListener() {
    @Override
    public void onCameraReady(UnicoCheckCameraOpener.Document cameraOpener) {
        cameraOpener.open(DocumentType.CNH, cameraListener);
    }

    @Override
    public void onCameraFailed(String message) {
        Log.e(TAG, message);
    }
});
val cameraListener: iAcessoBioDocument = object : iAcessoBioDocument {
    override fun onSuccessDocument(result: ResultCamera?) {}

    override fun onErrorDocument(errorBio: ErrorBio?) {}
}

unicoCheckCamera.prepareDocumentCamera(unicoConfig, object : DocumentCameraListener {
    override fun onCameraReady(cameraOpener: UnicoCheckCameraOpener.Document?) {
        cameraOpener?.open(DocumentType.CNH, cameraListener)
    }

    override fun onCameraFailed(message: String?) {
        Log.e(TAG, message)
    }
})

Prepare and open the camera


It is necessary to create an instance of the builder using the build() method. This method is provided through the object generated with the IAcessoBioBuilder interface and the AcessoBio class:

UnicoCheckCamera unicoCheckCamera = acessoBioBuilder.build();  
val unicoCheckCamera = acessoBioBuilder.build()

The next step is to prepare the camera using the prepareDocumentCamera() method with the object returned by the builder (named UnicoCheckCamera in the example above).

The prepareDocumentCamera() method generates an object of type UnicoCheckCameraOpener.Document, which is used to open the camera with its open() method, receiving the parameters for the type of document to be captured, which are:

Parameter
Description

DocumentCameraType.CPF

Frame for capturing the front of the CPF.

DocumentCameraType.CNH

Frame for capturing the open CNH.

DocumentCameraType.CNH_FRENTE

Frame for capturing the front of the CNH.

DocumentCameraType.CNH_VERSO

Frame for capturing the back of the CNH.

DocumentCameraType.RG_FRENTE

Frame for capturing the front of the RG.

DocumentCameraType.RG_VERSO

Frame for capturing the back of the RG.

DocumentCameraType.None

Frame for capturing any other document.

If you need to capture a document for which we don't have a specific frame (e.g., RNE, among others), use the DocumentCameraType.None frame, which will provide you with a generic, rectangular frame that can be used to guide any capture.

onSucessDocument Method


When an image capture is successful, this method is invoked and returns an object of type ResultCamera, which is later used in the REST API calls:

public void onSuccessDocument(ResultCamera result) { }

The ResultCamera object returns two attributes: base64 and encrypted:

  • The base64 attribute can be used if you want to display a preview of the image in your app.

onErrorDocument Method


When an error occurs during image capture, this method is invoked and returns an object of type ErrorBio:

public void onErrorDocument(ErrorBio errorBio) { }

Making a POST Request to the Client API



This method is invoked with a parameter of type ErrorBio, which contains details about the error. Learn more about the ErrorBio type in the section.

Both the encrypted and base64 attributes can be sent in the REST API calls to .

If it's necessary to convert base64 to bitmap, the standard method doesn't work for Android. You need to perform a split at the comma (,) for it to work. If you'd like to learn more, read the article

Learn more about the ErrorBio types in the section of the SDK.

Capturing the images is just the first part of the journey. After capturing the image, it is necessary to send the base64 generated by the SDK to the by Client REST APIs. Learn more in the

Still need help?

Didn't find something or still need help? If you're already a client or partner, you can reach out through our .

error handling
by Client
How to convert a Base64 string into a Bitmap image to show it in an ImageView?.
error handling
CreateProcess section of by Client.
​
Help Center
Android Customization