Skip to main content

Document capture

About this guide

This guide is designed to assist you in the integration with the Android SDK in a fast and easy way. On this page, you find some key concepts, implementation examples, as well as how to interact with the Biometric Engine REST APIs.

Please note

Please note that this guide focuses on the image capture process. For more information about the REST APIs of Unico Check, please refer to REST API Reference guide.

Following this guide, you are able to:

  • Learn how to open user's camera and capture an image;
  • Learn how to link the parameters returned by the SDK with the REST APIs;
  • Learn how to deal with the data returned by the REST API;

Before you begin

The step-by-step instructions on Getting started guide to set up your account, get your API key and install the SDK must be completed. It is also recommended that you check the available features of this SDK on the Overview page.

Available resources

This SDK offers a component that allows you to capture optimized images in your app, displaying to your users a silhouette that gets automatically adjusted to the size of their screens. You can capture the following documents with the SDK:

  • CPF: Brazilian national ID Document (CPF);
  • CNH: Brazilian Driver's licence - Opened document, front and back;
  • CNH Front: Brazilian Driver's licence - Front;
  • CNH Back: Brazilian Driver's licence - Back;
  • RG Front: Brazilian regional ID Document (RG) - Front;
  • RG Back: Brazilian regional ID Document (RG) - Back;
  • Other: Any kind of document.
Captura Manual
Capture frame customization

We offer you the possibility of customizing the capture frame in the SDK. To customize it, you just need to use the method corresponding to the property to be customized and apply the change with the setTheme() method.

Learn more about the setTheme() method and the customization possibilities at Android´s SDK reference documentation.

Implementation

Follow the steps below to have the full potential of the SDK embedded in your app in just some few minutes:

  1. Initialize the SDK

    First, you have to instantiate the builder, through the interface UnicoCheckBuilder.

    class _MyHomePageState extends State<MyHomePage> implements UnicoListener {

    late UnicoCheckBuilder _unicoCheck;

    /// Unico callbacks
    @override
    void onErrorUnico(UnicoError error) {}

    @override
    void onUserClosedCameraManually() {}

    @override
    void onSystemChangedTypeCameraTimeoutFaceInference() {}

    @override
    void onSystemClosedCameraTimeoutSession() {}

    /// Document callbacks
    @override
    void onSuccessDocument(ResultCamera resultCamera) { }

    @override
    void onErrorDocument(UnicoError error) { }

    }

    This implementation can be done with just some lines of code. Override the callback functions with your business rules. Each one of the callback functions is invoked as detailed below:

    onErrorUnico(UnicoError error)

    This callback function is invoked whenever an implementation error happens. For example, when informing an incorrect or inexistent capture mode while configuring the camera.

    Once invoked, this callback function receives an object of type ErrorBio containing the error details. Learn more about the type ErrorBio in the Flutter SDK references document.

    onUserClosedCameraManually()

    This callback function is invoked whenever an user manually closes the camera. For example, when clicking on the "Back" button.

    onSystemClosedCameraTimeoutSession()

    This callback function is invoked whenever the session timeout is reached (Without capturing any image).

    Session Timeout

    The session timeout can be set with the builder using the setTimeoutSession method. The session timeout must be configured in seconds.

    Be careful

    All the above callback functions must be declared in your project (Even without any business rules). Otherwise, you won't be able to compile your project.

  2. Open the camera

    Finally, let´s open the camera! To make it easier, this last piece is splitted in some steps.

    Implementing the listeners

    Through the implementation of listeners, you can configure what happens in your App in both error or success cases when capturing an image, using the methods onSuccessDocument or onErrorDocument, respectively.

    onSuccessDocument Method
    public void onSuccessDocument(ResultCamera resultCamera) { }

    This method is invoked whenever an image is successfully capture. Once invoked, this function receives an object of type ResultCamera that is used latter to call the Unico Check Rest APIs.

    onErrorDocument Method
    public void onErrorDocument(UnicoError error) { }

    This method is invoked whenever an error happens while capturing an image. Once invoked, this callback function receives an object of type ErrorBio containing the error details. Learn more about the type UnicoError at Flutter SDK references document.

    Listeners implementation

    The implementation of these listeners must be done inside an instance of the class UnicoDocument.

    Customize the capture frame

    Optional step

    This step is optional but recommended.

    We offer you the possibility of customizing the capture frame in the SDK. To customize it, you just need to use the method corresponding to the property to be customized and apply the change with the setTheme() method.

    Learn more about the method setTheme() and the customization possibilities at Flutter SDK reference documentation.

  3. Abrir a câmera

    Finally, we must open the camera with the settings done until this step. To that, we must call the openCameraDocument() method.

    Then, we must open the camera using the openCameraDocument() method, that was generated by the object from the class UnicoCheck. This method must receive as parameter:

    • JSON file with your credentials, generated at this step.
    • Type of document to be capture:
      • DocumentCameraType.CPF: Brazilian national ID Document (CPF);
      • DocumentCameraType.CNH: Brazilian Driver's licence - Opened document, front and back;
      • DocumentCameraType.CNH_FRENTE: Brazilian Driver's licence - Front;
      • DocumentCameraType.CNH_VERSO: Brazilian Driver's licence - Back;
      • DocumentCameraType.RG_FRENTE: Brazilian regional ID Document (RG) - Front;
      • DocumentCameraType.RG_VERSO: Brazilian regional ID Document (RG) - Back;
      • DocumentCameraTypes.NONE("description"): Any kind of document, without silhouette. In this case you must include the name of the document as a description to be displayed in the frame;
    • The listeners configured above;

    Example capturing a CNH:

     _unicoCheck.build().openCameraDocument(
    jsonFileName: androidJsonFileName,
    documentType: DocumentType.CNH,
    listener: this);

    A successful response would include the object ResultCamera with the following attributes:

    • base64: This attribute can be used in the case you want to display a preview of the captured image in your app;
    • encrypted: This attribute must be sent to the unico check REST APIs as detailed here;
  4. Call the REST APIs

    The image capture is just the first step of the journey. Now, you have to send the obtained JWT to the Rest APIs using one of the available flows, detailed in this page.

Getting help

Are you missing something or still need help? Please, please get in touch with the support team at help center.

Next steps