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 quickly and easily implement the Android SDK. Below, you'll find the step-by-step process for the complete integration. If you wish to customize the experience further, check out the Android Customization section.

Initializing the SDK


Create an instance of the builder (generated through the IAcessoBioBuilder interface), providing the relevant context and implementing the AcessoBioListener class. The implementation of this class is straightforward and can be achieved with just a few lines of code. Simply instantiate the builder with the relevant context and override the callback methods with your application’s business logic:

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 to run the SDK. Use the enumerated environment that contains the following enumerates:

  • 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 implementing the AcessoBioListener class is largely about setting up callback methods. Each method is triggered in a specific SDK return scenario. Override the methods exemplified above with your application’s business logic.

1

onErrorAcessoBio(ErrorBio errorBio)

This method is invoked whenever any implementation error occurs using any SDK method. It receives an ErrorBio parameter that contains error details. See the Error Handling section for more about ErrorBio.

2

onUserClosedCameraManually()

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

3

onSystemClosedCameraTimeoutSession()

This method is invoked when the maximum session time is reached (without capturing an image).

You can configure the session timeout in seconds using setTimeoutSession. The default and minimum timeout is 40 seconds.

4

onSystemChangedTypeCameraTimeoutFaceInference()

This method is invoked when the maximum time for face detection is reached without detection.

The maximum time is 13 seconds. The mode is then switched to manual capture to facilitate the user’s action.

All the above methods must be created as indicated in your project (even without any logic); otherwise, the project won’t compile successfully.

Configuring Camera Mode


The SDK is preconfigured with intelligent framing and automatic capture. Configure the camera mode in the builder as follows:

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

The false/true values in the above methods do not alter the capture experience; they are solely used for the SDK's internal logic.

Implementing Listeners for Camera Events


Implement these listener methods using an instance of the iAcessoBioSelfie class

The camera opening method, which is called in the next step, needs to know what to do when an image is successfully captured or if an error occurs in the process. You must specify "what to do" in the camera opening method by implementing listeners, which are triggered in success or error situations.

Through listener configuration, you can define what happens in your app in cases of an error (onErrorSelfie method) or success (onSuccessSelfie method) when capturing images.

To configure the listeners, you need 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);
    }
});

onSucessSelfie Method


Upon successful image capture, this method returns a ResultCamera object for subsequent API requests:

public void onSuccessSelfie(ResultCamera result) { }

The ResultCamera object provides two attributes: base64 and encrypted:

  • Use base64 for preview in the app;

  • Use encrypted for sending to REST APIs.

  • The encrypted attribute is strictly intended for sending the image through the by Client APIs. It should not be opened or serialized, as its characteristics may change without prior notice. Its use must be exclusive to interactions with the APIs to ensure the integrity and security of the data. Unico is not responsible for any damages arising from this practice, as modifications may occur unexpectedly.

  • The base64 and encrypted files can vary in size due to several factors, including the quality of the devices and the photos generated, as well as Unico's business rules. To avoid issues in your application, do not restrict the size of the string generated by the SDK for these files in your programming logic or infrastructure.

If it is necessary to convert the base64 string to a bitmap, the standard method does not work for Android. You need to perform a split at the comma (,) for it to function correctly. If you want to learn more, read the article: How to convert a Base64 string into a Bitmap image to show it in a ImageView?.

onErrorSelfie Method


If an error occurs during image capture, this method returns an ErrorBio object

public void onErrorSelfie(ErrorBio errorBio) { }

Learn more about ErrorBio types in the SDK Error Handling section.

Preparing and Opening the Camera


The openCameraSelfie method is used to open the camera. This method receives as a parameter the implementation of the UnicoSelfie class and the JSON with the credentials, generated in the step above.

The following example illustrates the steps for configuring listeners and opening the camera:

_opener.openCameraSelfie(jsonFileName: androidJsonFileName, listener: this)

Making a POST Request to the Client API


After capturing images, the next step is to send the generated encrypted image from the SDK to the Client APIs.

For security reasons, the interval between the generation of the encrypted data and the sending through one of the available flows must be no more than 10 minutes. Submissions made beyond this period will be automatically rejected by the API.


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.

Atualizado

Institucional

Sobre nós

Copyright © 2024 unico. All rights reserved