DocumentDetector v8.x or above

Current Version

In upcoming releases, we'll update to the following versions:

  • Kotlin from 1.5.32 to 1.9.10

  • AGP: from 4.1.0 to 8.3.2

  • Gradle: from 6.9.1 to 8.4

Requirements

  • Minimum Android SDK API version: minSdk 26 (Android 8 Oreo)

  • Android SDK API version to compile: compileSdk 34

Runtime permissions

SDK size

The SDK size is approximately 3.3 MB, which may decrease due to these elements.

Installation

If your version of Gradle is earlier than 7, add these lines to your build.gradle.

allprojects {
  repositories {
  ...
  maven { url 'https://repo.combateafraude.com/android/release' }
  maven { url 'https://jitpack.io' }

}}

If your version of Gradle is 7 or newer, add these lines to your settings.gradle.

dependencyResolutionManagement {
    repositories {
        ...
        maven { url 'https://repo.combateafraude.com/android/release' }
        maven { url 'https://jitpack.io' }
    }
}

Add support for Java 8 (skip this code if Java 8 is enabled), Data Binding and TensorFlow Model to your build.gradle file.

android {
    ...
    // Enable Data Binding, depending on the version of com.android.tools.build:gradle
    // If com.android.tools.build:gradle >= 4
    buildFeatures {
        dataBinding = true
    }
    // If com.android.tools.build:gradle < 4
    dataBinding.enabled = true

    // Java 1.8 compatibility, allowing lambda functions
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    aaptOptions {
        noCompress "tflite"
    }
}

As our SDKs activities use Data Binding, it is required that you enable this setting within your app. The compileOptions setting is required for SDK's built-in lambda functions, which were released in Java 8. The noCompress setting tells the compiler not to compress files with the .tflite extension used in the DocumentDetector.

Add the SDK version to the dependencies section in your build.gradle file

dependencies {
    implementation 'com.combateafraude.sdk:document-detector:{version}'
}

Supported documents

Currently, supported documents are:

public enum Document {
    RG_FRONT, // front of RG (where the photo is located)
    RG_BACK, // back of RG
    RG_FULL, // RG opened (showing front and back together)
    CNH_FRONT, // front of CNH (where the photo is located)
    CNH_BACK, // back of CNH 
    CNH_FULL, // CNH opened (showing front and back together)
    CRLV, // CRLV
    RNE_FRONT, // front of RNE or RNM
    RNE_BACK, // back of RNE or RNM
    PASSPORT, // passport (showing the photo and data)
    CTPS_FRONT, // front of CTPS (where the photo is located)
    CTPS_BACK, // back of CTPS
    ANY; // allows you to send any type of document, all those mentioned above, including any other document, as there are no typifications
}

Instantiating the SDK

First things first, instantiate an object of type DocumentDetector. This object will contain all your business rules for the SDK:

DocumentDetector mDocumentDetector = new DocumentDetector.Builder(String mobileToken)
    // see table below
    .build();

All parameters annotated with @Nullable can receive null values, useful if you want to configure only one of the parameters of the same method.

Builder method

DocumentDetectorStep

To create a capture flow, you will need to create an array of DocumentDetectorStep, where each element will be a capture step. To construct each DocumentDetectorStep object, you can enter the following elements:

DocumentDetectorStep detectorStep = new DocumentDetectorStep(Document.RG_FRONT);

CaptureStage

To improve the client's UX, we recommend creating difficulty stages for the DocumentDetector. For this, we offer the CaptureStage object, where you can set the following parameters:

Since the .setCaptureStages parameter is not required, if it is not used, the DocumentDetector will use this default:

new CaptureStage[]{
    new CaptureStage(CaptureMode.AUTOMATIC, 30000L, true),
    new CaptureStage(CaptureMode.AUTOMATIC, 15000L, false),
    new CaptureStage(CaptureMode.MANUAL, null, false)
}

UploadSettings

To enable the document upload functionality it is necessary to instantiate an object of type UploadSettings(boolean enable) and set its parameters:

Currently, the supported file formats are:

public enum FileFormat {
    PNG("image/png"),
    JPG ("image/jpg"),
    JPEG ("image/jpeg"),
    PDF("application/pdf"),
    HEIF("image/heif");
}

MessageSettings

To use, simply instantiate a MessageSettings object and use the methods as needed for customization.

Example

MessageSettings messageSettings = new MessageSetings()
    .setFitTheDocumentMessage(R.string.exempleFit)
    .setHoldItMessage(R.string.exempleHoldIt);

Security validations

We are constantly taking actions to make the product more and more secure, mitigating a number of attacks observed in the capture process and, consequently, reducing as many possible identity frauds as possible. The SDK has some blocks that may prevent its execution in certain contexts. To disable them, you can use the methods as shown in the example below:

DocumentDetector.Builder("mobileToken")
    .setUseDeveloperMode(true)
    .setUseAdb(true)
    .setUseDebug(true)
    .build();

Disabling security validations is recommended for testing purposes only. For publishing your application in production, we recommend using the default settings.

Starting Activity

After creating the DocumentDetector, start the DocumentDetectorActivity by passing this object as a parameter via extra intent:

Intent mIntent = new Intent(context, DocumentDetectorActivity.class);
mIntent.putExtra(DocumentDetector.PARAMETER_NAME, mDocumentDetector);
startActivityForResult(mIntent, REQUEST_CODE);

Getting the result

To get the DocumentDetectorResult object, which contains the captures taken by the SDK, override the onActivityResult method in the same Activity that you started the DocumentDetectorActivity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE){
        if (resultCode == RESULT_OK && data != null){
            DocumentDetectorResult mDocumentDetectorResult = (DocumentDetectorResult) data.getSerializableExtra(DocumentDetectorResult.PARAMETER_NAME);
            // check mDocumentDetectorResult.getSDKFailure() to find out why the SDK was terminated
        } else {
            // the user closed the activity
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

DocumentDetectorResult

Capture

Last updated

Logo

2023 © Caf. - All rights reserved