Document Capture

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.

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);
}

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)

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

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).

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).

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);
    }
});

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();  

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.

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.

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

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) { }

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

Making a POST Request to the Client API

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.

Last updated

Was this helpful?