Android Advanced SDK

Android Advanced SDK

*This feature is in early release.

A set of components meant to provide the full functionality of Berbix ID verification, while allowing customers to use their own UI.

Customers who want a drop-in ID verification solution with minimal code should look into the Berbix Android SDK, which provides a full ID verification flow in your app in just a few lines of code. The Berbix Android SDK comes with basic themeing and color customization options.

This Advanced SDK is built for customers who want their app's ID verification flow to have a more customized UI and brand identity. This SDK allows you to build you own UI for your app's ID verification flow, while utilizing Berbix to interact with the device's camera and leveraging Berbix's machine learning to take a photo at the most optimal moment.

Different classes in this SDK correspond to the different types of ID verification you app might need e.g. driver's license scan, selfie check, etc.

❗️

This documentation assumes you are familiar with the Berbix API-Only verification flow. If you have not yet reviewed our API-Only Integration Guide, please do so now.

The best way to learn about how to use this Advanced SDK (besides reading this documentation), is to look at the example app. The example app implements this SDK in the most common configurations, so it's easy to copy/paste code from the Fragments in the example app, and start using them in your own app.

Getting Started

To get started, simply add the Berbix Advanced SDK to your module dependencies:

dependencies {
  ...
  implementation 'com.berbix:berbixadvanced:1.0.0'
  ...
}

A gradle sync of the project in Android Studio might be required to download the library and allow Android Studio to find it.

Because this SDK takes photos, you will also need to check for camera permissions and ask for them if the user hasn't granted them yet.

Take a look at the "Request camera permissions" section in HomeFragment of the example app for an example of checking for and requesting camera permissions.

Note: Starting this SDK without being granted camera permissions will result in a blank screen where the camera preview should be, preventing users from taking a photo and completing the ID verification process.

Completing an ID verification

This SDK is meant to be used in conjunction with an API-only integration with Berbix. See these docs on an API-only integration with Berbix. You'll use the Berbix API to grab a client token, which you'll need to finish the rest of the ID verification flow. The output of this Advanced SDK will be photos of e.g. the user's ID or face, and you'll need to submit the photos to Berbix using the API-only integration instructions at the link above.

Using the Advanced SDK

The only UI the Advanced SDK provides is a camera preview, so users can see what they are taking a photo of, without you having to write any code to interact with the device's camera directly. You'll need a new Fragment to show the camera preview, as well as any other UI you want to show.

Depending on what you need your user to take a photo of, make sure your Fragment class subclasses one of the following classes from the Advanced SDK:

  • DocumentCameraFragment
  • BarcodeScannerFragment
  • SelfieCameraFragment

The three base classes above correspond to the main types of items a user might have to take a photo of to complete an ID verification flow. DocumentCameraFragment is for documents e.g. driver's licenses, passports, etc. BarcodeScannerFragment is for barcodes and QR codes, typically found on the back of some forms of ID. SelfieCameraFragment is for the Selfie and Liveness Check parts of the ID verification flow.

To show the camera preview to your user, place the following component in your fragment's layout:

<com.berbix.advanced.BerbixCameraView
        android:id="@+id/berbix_camera_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Back in your Fragment, you will be required to override berbixCameraView with the ID of your BerbixCameraView component, in this example berbix_camera_view.

Convenience Methods

The following methods expose functionality that may be useful to your users:

  • toggleFlashlight() - turns the device's flashlight (torch) on or off. Note that this does nothing if the user is using the front-facing camera, except on some devices which may have a front-facing flashlight.
  • flipCameraDirection() - Toggles between the front and back cameras. In most cases, the appropriate camera will be chosen for you i.e. SelfieCameraFragment uses the front camera by default, and
    the other fragments use the rear camera by default. However if you want to allow your user to change the camera, use this method.
  • stopCamera() - Call this to stop the currently running camera and its analyzer. In most cases, calling this won't be necessary as the sdk handles shutting down the camera and associated resources for you.
  • var cameraFacing - override this if you want to change the default camera (front or back) that the user sees when they first navigate to your Fragment.

Autocapture

"Autocapture", in this context, means utilizing Berbix's machine learning to automatically take a photo at the most optimal moment. For example in a Selfie Camera, that would be when the user's face is at the right angle, or in a Barcode scanner, it's when the barcode is fully visible and well-lit.

You can optionally turn Autocapture off by overriding var autocaptureOn and setting it to false.
Note that if you turn Autocapture off, you'll need to give your users some way to take a photo e.g. a "Take Photo" button.

Leaving Autocapture on is recommended in most cases, however there are cases in which you may be required to turn Autocapture off. For example, users in the U.S. states of Texas, Illinois, and Washington should be given the option to opt-out of facial recognition. See this documentation for more.

Taking a photo

Call startCamera() in your Fragment's onCreate method. Be sure to wrap it in a try/catch in case opening the camera doesn't work. If there is a problem opening the camera, it may be best to provide some fallback, such as letting the user upload an existing photo from the device's file picker.

Listen for the photo in onPhotoCaptured(image: Image). The Image class is a built-in class in android.media that represents a JPEG that you can upload to Berbix using the Berbix API as described above.

If Autocapture is off, call takePhoto() to take the photo. With Autocapture on, takePhoto() gets called in the background for you at the right moment.