DocumentDetector v8.x or above
Current Version
The following versions have been used since version 9.0.0:
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
Name | Version |
---|---|
| 9.1.2 |
Requirements
Minimum Android SDK API version:
minSdk 26
(Android 8 Oreo)Android SDK API version to compile:
compileSdk 34
Runtime permissions
Permission | Reason | Required? |
---|---|---|
| To capture photos of the documents. | Only for capture feature. |
| To access the device external storage and select documents in the upload flow. | Only for upload feature. |
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
.
If your version of Gradle is 7 or newer, add these lines to your settings.gradle
.
Add support for Java 8 (skip this code if Java 8 is enabled), Data Binding and TensorFlow Model to your build.gradle
file.
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
Supported documents
Currently, supported documents are:
Instantiating the SDK
First things first, instantiate an object of type DocumentDetector
. This object will contain all your business rules for the SDK:
All parameters annotated with
@Nullable
can receivenull
values, useful if you want to configure only one of the parameters of the same method.
Builder method
Parameter | Required |
---|---|
Token associated with your account, to use the SDK. | Yes. |
Defines the document capture flow as explained here. | Yes. |
User identifier for fraud profile identification purposes and to assist in the identification of Analytics logs in cases of bugs and errors. | No. |
Configures the requirements for each capture stage. Designed to make capture more flexible in cases where the user is unable to capture with all checks active, preventing them from getting stuck at this stage in their registration flow. Configure it as you prefer by following this example. | No. |
Enables/disables the popups displayed before each document capture. | No. The default value is |
Overrides the default SDK layout. Create a file in the layout folder of your project, copy this template and make the changes you want. | No. |
Set up a new style guideline for the SDK. Create a | No. |
Defines SDK's requests timeout. | No. The default value is |
Defines threshold between acceptable/unacceptable ambient brightness. Set | No. The default settings are |
Defines threshold between correct/incorrect device orientation. Higher the value more flexible it will be. Set | No. The default setting is |
Defines stability sensor settings. Set | No. The default setting is time |
Defines proxy settings. Follow this guide. | No. The default setting is |
Enables/disables and allows the configuration of the visualization of the capture performed, requesting the user's confirmation to proceed. | No. The default is disabled. |
Delays the activity after the completion of each step. This method can be used to display a success message on the screen itself after the capture, for example. | No. The default is |
Allows customizing messages displayed in the feedback label during the capture and analysis process. See the available attributes here. | No. |
Allows you to set the capture resolution. The method takes as parameter a
| No. The default is |
Allows you to configure the quality in the compression process. By default, all captures go through compression. The method expects values between 80 and 100 as a parameter, where 100 is the best quality compression. | No. The default is |
Allows you to enable/disable features of the SDK that consume GoogleServices in the SDK, we do not recommend disabling the services because of the loss of security. | No. The default is |
Enables the use of developer mode when | No. The default is |
Enables Android Debug Bridge (ADB) debugging mode when | No. The default is |
Allows you to use the app in debug mode when | No. The default is |
Sets the time the image URL will last on the server until it is expired. Expect to receive a time interval between "30m" to "30d". Examples:
| No. The default is |
Sets the settings for uploading documents. By enabling this option, the SDK flow will prompt the user to upload the document files instead of capturing them with the device's camera. This option also includes document type and quality checks. See how to set it here. | No. By default this option is disabled. |
Enables the option to allow passports from only a certain issuing country, or, a list of countries. See the complete list at: ISO 3166-1 alpha-3. Example:
| No. Passports issued by any country are accepted by default. |
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:
Parameter | Required? |
---|---|
Identifies which document you want to capture in the respective step. See supported document types here. | Yes. |
Defines text to be shown in the lower part of the layout. | No. There is a pattern by |
Defines illustration to be shown in the popup prior to capture. | No. There is a pattern by |
Present the text to be displayed at the top of the layout | No. the default is |
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:
Parameter |
---|
Document capture mode, which can be |
Duration of the stage, in milliseconds. If you do not want a timeout, parameterize |
Enables/Disables the use of sensors for capturing the photo. |
Since the .setCaptureStages
parameter is not required, if it is not used, the DocumentDetector
will use this default:
UploadSettings
To enable the document upload functionality it is necessary to instantiate an object of type UploadSettings(boolean enable) and set its parameters:
Parameter | Required? |
---|---|
Enables/disables this feature. | No. The default is |
Enables/disables file compression before uploading. | No. The default is |
Defines the file format(s) that will be accepted for upload. | No. By default |
Sets the maximum KB limit of the file to upload. | No. The default limit is 10000 KB (10MB). |
Defines the background layout of the document upload. | No. |
Defines the layout of the document upload request popup. | No. |
Currently, the supported file formats are:
MessageSettings
To use, simply instantiate a MessageSettings
object and use the methods as needed for customization.
Method | Default value |
---|---|
Message displayed in the subtitle of the pop-up that brings the illustration of the document that is being requested for capture. | โDispose the document in a desk, centralize it on the markup and hold the automatic capture.โ |
Message telling you to fit the document to the mask. | "Fit the document on the markup" |
Message displayed at the moment the capture is being performed. | "Keep it that way" |
Message displayed when the SDK makes a request to the backend, checking for quality. | "Checking document..." |
Message displayed when the capture quality fails. | "Ops, could not read the information. Please try again." |
Message displayed when there is no quality check and the capture is being saved on the servers. | "Sending image..." |
Message displayed when displaying an open document, the message will be displayed together with the error message on the document being used, example: if the user displays an open CNH(Brazilian driveโs license), the standard error message "Essa รฉ uma CNH Aberta" + the defined message will be displayed. | "Close your document and try again" |
Message displayed when you start the camera. | "Please wait..." |
Message displayed when the brightness threshold is lower than expected. | "Area near you is too dark" |
Message displayed when the orientation threshold is lower than expected. | "Point the camera down" |
Message displayed when the orientation threshold is lower than expected. | "Keep the device still" |
Message displayed when the document is displayed in a different stream than expected. "%1$s" is optional if you want to add de expected document in your message | "Ops, this document is not %1$s" |
Allows for customization of the confirmation button message. | "OK, understood" |
Sets the title of the upload popup when the uploaded file exceeds the maximum allowed size. | "File size exceeded" |
Sets the upload popup message when the uploaded file exceeds the maximum allowed size. The variable | "It looks like the file you chose exceeds the maximum permitted. Try to upload a smaller file with a maximum size of |
Sets the title of the upload popup when the format of the uploaded file is not valid. | "Invalid format." |
Sets the upload popup message when the format of the uploaded file is not valid. | "It looks like the file's format is not supported. Try uploading a new file in JPG, PNG or PDF format." |
Sets the generic error title for the upload popup. | "Ops, something went wrong." |
Sets the generic error message for the upload popup. | "It looks like this isn't the expected document. Upload a photo of the requested document type." |
Sets the title of the upload popup when the quality of the uploaded image fails. | "Ops, low quality picture" |
Sets the upload popup message when the quality of the uploaded image fails. | "The document's quality appears to be very low. Try uploading a better quality picture." |
Sets the message displayed in the upload popup while the file is being uploaded. | "Sending your document" |
Message displayed to request a document to be present on the camera. | "Scan a document" |
Message displayed to request to get closer to the document. | "Move the document closer" |
Message displayed to request to center the document. | "Center the document" |
Message displayed to request to move away from the document. | "Move away from the document" |
Message displayed to request to align the document. | "Align the document" |
Message displayed to request to turn document 90 degrees. | "Turn the document โคต๏ธ" |
Message displayed to alert that the document was captured. | "Document captured" |
Message displayed to alert that the document was not supported. | "Ops, it seems that this document is not supported." |
Message displayed to alert that the document was not found. | "Didn't found a document." |
Example
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:
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:
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
:
DocumentDetectorResult
Parameter | Allow null |
---|---|
The array with the respective captures of the parameterized documents. | Yes, in case of error |
The class of the read document stream. This parameter is useful in an integration with our OCR route. The existing types are: | Yes, in case of error. |
Identifier of this execution on our servers. If possible, save this field and send it along to our API. This way we will have more data on how the user behaved during the execution. | No |
Object that tells you the reason for the SDK shutdown. For more information, see here. | Yes, in case of success. |
Capture
Parameter | Can it be null? |
---|---|
Full path of the image on the user's device. | No. |
URL of the document on the Caf's server. This URL has an expiry time, which can be set with the | No. |
Label of the respective document within the following possibilities: | No. |
Quality inferred by the document quality algorithm. Varies between 0 and 5. | No. |
Last updated