Selfie Capture

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


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

Initializing the SDK


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

The implementation of this class is quite simple and can be done in just a few lines of code. All you need to do is instantiate the builder by providing the relevant 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);
}

Environment configuration


Configure the environment that will be used during the SDK execution. Use the Environment enum, which contains the following options:

  • Environment.PROD: for production environment;

  • Environment.UAT: for approval environment.

See how to implement it in the example below:

acessoBioBuilder.setEnvironment(Environment.UAT);

Implementing Callback Functions


Note that the work of implementing the AcessoBioListener class is, for the most part, 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.

This method is invoked whenever any implementation error occurs while using one of our methods:

1

onErrorAcessoBio(ErrorBio errorBio)

When invoked, the method receives a parameter of type ErrorBio that 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 when 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 face detection is reached (without detecting anything). In this case, the camera mode is automatically switched to manual capture mode (without the smart capture outline).

Configuring Camera Mode


The SDK has smart framing and automatic capture configured and enabled by default. As a result, you must configure the camera mode in your builder as follows:

UnicoCheckCamera unicoCheckCamera = acessoBioBuilder
    .setAutoCapture(true)
    .setSmartFrame(true)
    .build();

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 (onErrorSelfie method) or success situations (onSuccessSelfie method) during image capture.

To configure the listeners, it is necessary to implement:

iAcessoBioSelfie cameraListener = new iAcessoBioSelfie() {
    @Override
    public void onSuccessSelfie(ResultCamera result) { }

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

unicoCheckCamera.prepareCamera(unicoConfig, new CameraListener() {
    @Override
    public void onCameraReady(UnicoCheckCameraOpener.Camera cameraOpener) {
        cameraOpener.open(cameraListener);
    }

    @Override
    public void onCameraFailed(String message) {
        Log.e(TAG, message);
    }
});

Prepare and open the camera


To proceed with opening the camera, it is first necessary to prepare it using the prepareCamera method. This method receives as parameters the implementation of the CameraListener class, the class, or the JSON with the credentials generated in this step.

When the camera is prepared, the onCameraReady event is triggered, which receives an object of type UnicoCheckCameraOpener.Camera as a parameter.

It is necessary to override this method, opening the camera with the object received through the open() method. The open() method should receive as parameters the listeners configured in the previous steps.

onSucessSelfie Method


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

public void onSuccessSelfie(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.

  • The encrypted attribute must be sent in the REST API calls to by Client.

onErrorSelfie Method


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

public void onErrorSelfie(ErrorBio errorBio) { }

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

Making a POST Request to the Client API


Image capture is just the first part of the journey. After capturing the image, it is necessary to send the encrypted generated by the SDK to the by Client REST APIs. Learn more in the CreateProcess section of by Client.


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 Help Center.

Last updated

Was this helpful?