Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Repository files navigation

Note This Java based version of the SDK Example has been superceded by a Kotlin version, which can be found here

Vouched

GitHub releaseLicense

Run Example

Clone this repo and change directory to example

git clone https://github.com/vouched/vouched-android
cd vouched-android/example

Then, follow steps listed on the example README

Prerequisites

  • An account with Vouched
  • Your Vouched Public Key

Install

Add the package to your existing project

implementation 'id.vouched.android:vouched-sdk:1.2.0'

(Optional) Add barcode scanning

In order to use BarcodeDetect, you must add ML Kit Barcode Scanner.
Note: you can choose between the bundled and unbundled model. Our experience is that the bundled model provides more accurate barcode scans. See the above ML Kit link for more information

// Use this dependency to bundle the model with your app
implementation 'com.google.mlkit:barcode-scanning:17.0.2' // Use this dependency to use the dynamically downloaded model in Google Play Services
implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.0'

(Optional) Add face detection

In order to use FaceDetect, you must add ML Kit Face Detection.
Note: you can choose between the bundled and unbundled model. The unbundled model will provide a smaller app footprint, but will require connectivity to download the model when verification is run or when the app is first installed.

// Use this dependency to bundle the model with your app
implementation 'com.google.mlkit:face-detection:16.1.4' // Use this dependency to use the dynamically downloaded model in Google Play Services
implementation 'com.google.android.gms:play-services-mlkit-face-detection:17.0.0'

Getting Started

This section will provide a step-by-step path to understand the Vouched SDK through the Example.

  1. Get familiar with Vouched

  2. An overview of SDK components

  3. Run the Example

    • Go through the verification process but stop after each step and take a look at the logs. Particularly understand the Job data from each verification step.
    System.out.println(job.toJson());
  4. Modify the Listeners

  5. Tweak CameraX settings
    Better images lead to better results from Vouched AI

  6. You are ready to integrate Vouched SDK into your app

SDK Reference

VouchedCameraHelper

This class is introduced to make it easier for developers to integrate VouchedSDK and provide the optimal photography. The helper takes care of configuring the capture session, input, and output. Helper has following detection modes: 'ID' | 'FACE' | 'BARCODE' | 'ID_BACK'.

Initialize
VouchedCameraHelpercameraHelper = newVouchedCameraHelper(this, this, ContextCompat.getMainExecutor(this), previewView, VouchedCameraHelper.Mode.ID, newVouchedCameraHelperOptions.Builder()
.withCardDetectOptions(newCardDetectOptions.Builder()
.withEnableDistanceCheck(false)
.withEnhanceInfoExtraction(false) .withEnableOrientationCheck(false)
.build())
.withCardDetectResultListener(this)
.withBarcodeDetectResultListener(this)
.withCameraFlashDisabled(true)
.withTimeOut(3000, timeoutListener)
.build());
Parameter TypeNullable
android.content.Contextfalse
androidx.lifecycle.LifecycleOwnerfalse
java.util.concurrent.Executorfalse
androidx.camera.view.PreviewViewfalse
VouchedCameraHelper.Modefalse
VouchedCameraHelper.Optionsfalse

Enhanced ID Info Extraction The camera helper can increase your verification abilities by recognizing additional sources of information based on the type of ID that your user submits. You can enable this behavior by using .withEnhanceInfoExtraction(true) when you create the camera helper.

Once enabled, the helper can help guide the ID verification modes by processing job results returned by the Vouched api service, and generating the appropriate modes that are needed to complete ID verification.

In terms of workflow, once the front ID has been imaged and uploaded, the Vouched service identifies the type if ID that is being used, and returns as part of response a JobResult object that informs the SDK as to other data extraction actions that may be taken. These additional actions can include extractions of data from one or more barcodes or capturing an image of the back of the ID for firther analysis.

In the current release, some coding is necessary - in your JobResponseListener callback, you first must verify that the job has no errors or insights (user feedback that requires more actions on the user's part before leaving a mode). If that proves to be true, pass the camera helper the results object and determine the next mode. Since you know what the next mode will be, this is a great point to dispay a dialog or provide other feedback to the user as to inform them as what to expect next.

onJobResonse changes:

// after verifying errors and insights, determine if the // ID requires other processing cameraHelper.updateDetectionModes(job.getResult());
// advance the mode to the next state.
VouchedCameraHelper.Mode next = cameraHelper.getNextMode();
// give the user feedback based on the next step

onCardDetectResult changes for back/frontside detection:

VouchedCameraHelper.Mode currentMode = cameraHelper.getCurrentMode();
if(currentMode.equals(VouchedCameraHelper.Mode.ID)) {
session.postFrontId(this, cardDetectResult, new Params.Builder().withFirstName(inputFirstName).withLastName(inputLastName), this);
} else if(currentMode.equals(VouchedCameraHelper.Mode.ID_BACK)) {
session.postBackId(this, cardDetectResult, null, this);
}

Note: The DetectorActivityWithHelper class in the example app shows how enhanced extraction can be implemented.

Enabling distance check

The camera helper can find for an ideal distance to capture the photo of the document by using .withEnableDistanceCheck(true) when setting you create the camera helper.

When this is enabled, the helper will guide us through instructions (passed through an OnDetectResultListener set by VouchedCameraHelperOptions.Builder.withCardDetectResultListener(OnDetectResultListener cardDetectResultListener) ) so that the user can move near or far his document from the camera.

Enabling orientation check

The camera helper can assist in guiding the user to an ideal ID document orientation by using .withEnableOrientationCheck(true) when setting you create the camera helper.

When this is enabled, the helper will guide the user through instructions (passed through an OnDetectResultListener set by VouchedCameraHelperOptions.Builder.withCardDetectResultListener(OnDetectResultListener cardDetectResultListener) ), so that the user can rotate their ID document to match the desired orientation.

Adding a timeout to ID scan

It is possible to set a timeout for how long to wait until an ID is captured, by using VouchedCameraHelperOptions.Builder.withTimeOut(Long timeInMilliseconds, TimeoutListener listener) (see TimeoutListener). When the timer expires the helper will stop looking for the ID, at which point it is possible to give the user the option to retry using vouchedCameraHelperInstance.clearAndRestartTimeout() or to manually capture the photo of his document using vouchedCameraHelperInstance.capturePhoto(imageCaptureListener) (see ImageCaptureListener).

CameraX

We recommend using CameraX with the Vouched SDK. The references will all use CameraX, and in the case of the VouchedCameraHelper, the CameraX apis are a dependency of that component.

VouchedSession

This class handles a user's Vouched session. It takes care of the API calls. Use one instance for the duration of a user's verification session.

Initialize
VouchedSessionsession = newVouchedSession("PUBLIC_KEY");
Parameter TypeNullable
Stringfalse
Initializing with token
VouchedSessionsession = newVouchedSession("PUBLIC_KEY", newVouchedSessionParameters.Builder().withToken("TOKEN").build());
POST Front Id image
session.postFrontId(this, cardDetectResult, newParams.Builder(), this);
Parameter TypeNullable
android.content.Contextfalse
CardDetectResultfalse
ParamsBuildertrue
JobResponseListenerfalse
POST Selfie image
session.postFace(this, faceDetectResult, newParams.Builder(), this);
Parameter TypeNullable
android.content.Contextfalse
FaceDetectResultfalse
ParamsBuildertrue
JobResponseListenerfalse
POST confirm verification
session.confirm(this,null,this);
Parameter TypeNullable
android.content.Contextfalse
ParamsBuildertrue
JobResponseListenerfalse

CardDetect

This class handles detecting an ID (cards and passports) and performing necessary steps to ensure image is POSTABLE.

Initialize
CardDetectcardDetect = newCardDetect(getAssets(), newCardDetectOptions.Builder().withEnableDistanceCheck(true)
.withEnhanceInfoExtraction(false)build(), this);
Parameter TypeNullable
android.content.res.AssetManagerfalse
CardDetectOptionsfalse
CardDetect.OnDetectResultListenerfalse
Process Image
cardDetect.processImageProxy(imageProxy, handler);
Parameter TypeNullable
androidx.camera.core.ImageProxyfalse
android.os.Handlerfalse

BarcodeDetect

This class handles detecting the encoded barcode data. Only applicable for ID and DL cards.

Initialize
BarcodeDetectbarcodeDetect = newBarcodeDetect(this);
Parameter TypeNullable
BarcodeDetect.OnBarcodeResultListenerfalse
Process Image
cardDetect.findBarcode(imageProxy);
Parameter TypeNullable
androidx.camera.core.ImageProxyfalse

FaceDetect

This class handles detecting a face and performing necessary steps to ensure image is POSTABLE.

Initialize
FaceDetectfaceDetect = newFaceDetect(this, newFaceDetectOptions.Builder().withLivenessMode(LivenessMode.DISTANCE).build(), this);
Parameter TypeNullable
android.content.Contextfalse
FaceDetectOptionsfalse
FaceDetect.OnDetectResultListenerfalse
Process Image
faceDetect.processImageProxy(imageProxy, graphicOverlay);
Parameter TypeNullable
androidx.camera.core.ImageProxyfalse
GraphicOverlaytrue

Types

CardDetectResult

The output from Card Detection and used to submit an ID. Note that CardDetectResults can arise from scanning the font or back of certain ID documents. It is currently the responsibility of the card detection callback to keep track of the mode the helper is in, and post to the correct endpoint. A future update will remove this requirement.

classCardDetectResult {
publicStepgetStep() { ... }
publicInstructiongetInstruction() { ... }
publicStringgetImage() { ... }
publicStringgetDistanceImage() { ... }
}

An example of handling front and back ID images in a card detection callback:

VouchedCameraHelper.Mode currentMode = cameraHelper.getCurrentMode();
if(currentMode.equals(VouchedCameraHelper.Mode.ID)) {
session.postFrontId(this, cardDetectResult, new Params.Builder().withFirstName(inputFirstName).withLastName(inputLastName), this);
} else if(currentMode.equals(VouchedCameraHelper.Mode.ID_BACK)) {
session.postBackId(this, cardDetectResult, null, this);
}
VouchedCameraHelperMode

An enum to provide detection modes for VouchedCameraHelper

enumMode {
ID,
BARCODE,
ID_BACK,
FACE,
COMPLETED
}
VouchedCameraHelperOptions

List of options to alter image processing for VouchedCameraHelper

VouchedCameraHelperOptionscameraOptions = newVouchedCameraHelperOptions.Builder()
.withFaceDetectOptions(newFaceDetectOptions.Builder()
.withLivenessMode(LivenessMode.MOUTH_MOVEMENT)
.build())
.withFaceDetectResultListener(this)
.build());
BarcodeDetectResult

The output from Barcode Detection and used to submit the encoded Barcode data.

classBarcodeResult {
publicStringgetValue() { ... }
publicStringgetImage() { ... }
}
FaceDetectResult

The output from Face Detection and used to submit a Selfie.

classFaceDetectResult {
publicStepgetStep() { ... }
publicInstructiongetInstruction() { ... }
publicStringgetImage() { ... }
publicStringgetUserDistanceImage() { ... }
}
ParamsBuilder

The builder for the parameters that are used to submit a Job.

classBuilder {
publicBuilderwithFirstName(StringfirstName) { ... }
publicBuilderwithLastName(StringlastName) { ... }
publicBuilderwithIdPhoto(StringidPhoto) { ... }
publicBuilderwithUserPhoto(StringuserPhoto) { ... }
publicBuilderwithUserDistancePhoto(StringuserDistancePhoto) { ... }
publicBuilderwithIdDistancePhoto(StringidDistancePhoto) { ... }
publicParamsbuild() { ... }
}
JobResponseListener

The listener to retrieve the Job data from the submission.

publicinterfaceOnJobResponseListener {
voidonJobResponse(JobResponseresponse);
}

Follow the below template

@OverridepublicvoidonJobResponse(JobResponseresponse) {
if (response.getError() != null) {
// handle app/network/system errors
} else { // see if there are recoverable job errorsJobjob = response.getJob();
List<Insight> insights = VouchedUtils.extractInsights(response.getJob());
// inform the user of the error extracted
}
// implement business and navigation logic based on Job data
}
CardDetectOptions

The options for Card Detection.

classBuilder {
publicBuilderwithEnableDistanceCheck(booleanenableDistanceCheck) { ... }
publicBuilderwithEnhanceInfoExtraction(booleanenableEnhancedIdScan) { ... }
publicBuilderwithEnableOrientationCheck(booleanenableOrientationCheck) { ... }
publicCardDetectOptionsbuild() { ... }
}
CardDetectResultListener

The listener to retrieve CardDetectResult.

interfaceOnDetectResultListener {
voidonCardDetectResult(CardDetectResultcardDetectResult);
}
BarcodeDetectResultListener

The listener to retrieve BarcodeDetectResult.

interfaceOnBarcodeResultListener {
voidonBarcodeResult(BarcodeResultbarcodeResult);
}
TimeoutListener

Listener to know when the timeout has expired when a document is being scanned, when this is executed the helper stops searching for documents or barcodes.

interfaceTimeoutListener {
voidonTimeout();
}
ImageCaptureListener

listener to know when a photo has been captured manually

interfaceImageCaptureListener {
voidonImageCapture(Bitmapbitmap);
}
FaceDetectOptions

The options for Face Detection.

publicenumLivenessMode {
MOUTH_MOVEMENT,
DISTANCE,
BLINKING,
NONE
}
classBuilder {
publicBuilderwithLivenessMode(LivenessModelivenessMode) { ... }
publicFaceDetectOptionsbuild() { ... }
}
FaceDetectResultListener

The listener to retrieve FaceDetectResult.

interfaceOnDetectResultListener {
voidonFaceDetectResult(FaceDetectResultfaceDetectResult);
}
RetryableError

An enum to provide an optional baseline of Verification Error(s) for a given Job.

enumRetryableError {
InvalidIdPhotoError,
InvalidUserPhotoError,
BlurryIdPhotoError,
GlareIdPhotoError
}

About

Legacy Java SDK for vouched on android

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages