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
  • Initializing the SDK
  • Environment configuration
  • Implementing Callback Functions
  • Configuring Camera Mode
  • Implementing Listeners for Camera Events
  • Prepare and open the camera
  • onSucessSelfie Method
  • onErrorSelfie 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

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

PreviousUsage and Integration GuideNextDocument Capture

Last updated 2 months ago

Was this helpful?


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

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

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

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

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 of the above methods must be created as indicated in your project (even if without any logic). Otherwise, the project will not compile successfully.

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();
val unicoCheckCamera: UnicoCheckCamera = acessoBioBuilder
    .setAutoCapture(true)
    .setSmartFrame(true)
    .build()

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

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.

Changes in naming conventions for versions lower than 4.2.1:

  • The method prepareCamera, which was previously prepareSelfieCamera.

  • The class CameraListener, which was previously SelfieCameraListener.

  • The object UnicoCheckCameraOpener.Camera, which was previously UnicoCheckCameraOpener.Selfie.

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);
    }
});
val cameraListener: iAcessoBioSelfie = object : iAcessoBioSelfie {
    override fun onSuccessSelfie(result: ResultCamera?) {}

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

unicoCheckCamera.prepareCamera(unicoConfig, object : CameraListener {
    override fun onCameraReady(cameraOpener: UnicoCheckCameraOpener.Camera?) {
        cameraOpener?.open(cameraListener)
    }

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

Prepare and open the camera


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 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 notice. Its use must be exclusive to interactions with the APIs to ensure data integrity and security. Unico is not responsible for any damages resulting from this practice, as modifications can occur unexpectedly.

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

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

Making a POST Request to the Client API


For security reasons, the interval between the generation of the encrypted and its submission via one of the available flows must be a maximum of 10 minutes. Submissions made beyond this period will be automatically rejected by the API.


When invoked, the method receives a parameter of type ErrorBio that contains details about the error. Learn more about the ErrorBio type in the section.

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.

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

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

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

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

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 .

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