TrustVision SDK is an android SDK for TrustVision Engine. It provides these features:
MainActivity.java
classTrustVisionSDK.init(this, YOUR_APP_KEY, YOUR_APP_SECRET, this);
tv_sdk.zip
, extract and put all files into a folder in android project.
Example: folder ${project.rootDir}/repo
app
root
repo
+--com
+--trustvision
+--tv_api_sdk
+--1.x.x
+--tv_api_sdk-1.x.x.aar
+--tv_api_sdk-1.x.x.pom
maven-metadata.xml
+--tv_sdk
...
build.gradle
repositories {
maven { url "https://maven.google.com" }
maven { url "path/to/tvsdk/folder" }
...
}
app/build.gradle
android {
...
aaptOptions {
noCompress "tflite"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('com.trustvision:tv_sdk:1.x.x@aar') {
transitive = true
}
testImplementation 'junit:junit:4.12'
}
To initialize the SDK, add the following lines to your app, and it needs to be completed successfully before calling any other SDK functionalities.
For example, you can add it to the onCreate
method of the application class.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TrustVisionSDK.init(this, appKey, appSecret, new TrustVisionSDK.TVInitializeListener() {
@Override
public void onInitSuccess() {
List<TVCardType> cards = TrustVisionSDK.getCardTypes();
}
@Override
public void onInitError() {
}
});
}
After the SDK is initialized, use this method to get list supported ID.
List<TVCardType> cards = TrustVisionSDK.getCardTypes();
Please note: The SDK requires Camera permissions to capture images. Camera permissions will be handled by the SDK if not already handled by the app.
where:
referenceID
can be a phone number or an opaque string that can be used for correlating API calls to TrustVision from host app.channelName
can be any string which is used to identify the running app.Start transaction should be called when start new user journey.
It needs to be completed successfully before calling Selfie/ID card capturing or Face Matching.
TrustVisionSDK.startTransaction(referenceID, channelName new TVTransactionCallback() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVTransactionData transactionData) {
HomeActivity.this.transactionID = transactionData.getTransactionId();
HomeActivity.this.channelId = transactionData.getChannelId();
}
});
where
TVTransactionData
.End transaction should be called when ending a user journey
The SDK provides some built in Activities example activity to capture id, selfie, liveness...
TVSDKConfiguration.Builder builder = new TVSDKConfiguration.Builder()
.setActionMode(TVActionMode.FULL)
.setLivenessMode(TVLivenessMode.PASSIVE)
.setEnableSound(true)
.setEnableTiltChecking(true)
.setCardType(selectedCard)
.setEnableReadCardInfo(false)
.setEnableIDSanityCheck(true)
.setEnableSelfieSanityCheck(true)
TVIDConfiguration configuration = builder.build();
Options:
TVActionMode
. Action modeTVCardType
. List of supported cards can be found by List<TVCardType> cards = TrustVisionSDK.getCardTypes();
Bool
. Sound should be played or notBool
. Check if the phone is paralize to the ground before taking the id card photo or notBool
. Check sanity of the id card photo or notBool
. Check sanity of the selfie photo or notBool
. Check id card tampering or notTVLivenessMode
. Liveness verification modeTVCameraOption
. Camera modeTVDefaultCameraSide
. Default camera sideTrustVisionActivity.startTrustVisionSDK(context, configuration, new TVIDCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
}
@Override
public void onCanceled() {
}
});
where:
TVCapturingCallBack
. It is an interface that has 3 methodonSuccess
method has one parameter.TVDetectionResult
. Use all public methods to get result detailsErrorCallback
CancellationCallback
The id capturing activity will show the camera to capture image, preview the image, upload image and then do OCR. To start the id capturing activity.
TVIDConfiguration.Builder builder = new TVIDConfiguration.Builder()
.setCardType(selectedCard)
.setBackside(false)
.setEnableReadCardInfo(false)
.setEnableSanityCheck(true)
TVIDConfiguration configuration = builder.build();
Options:
TVCardType
. List of supported cards can be found by List<TVCardType> cards = TrustVisionSDK.getCardTypes();
TVCardSide
. Card sideBool
. Sound should be played or notBool
. Check if the phone is paralize to the ground before taking the id card photo or notBool
. Check sanity of the id card photo or notTrustVisionActivity.startIDCapturing(context, configuration, new TVIDCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
}
@Override
public void onCanceled() {
}
});
where:
TVCapturingCallBack
. It is an interface that has 3 methodonSuccess
method has one parameter.TVDetectionResult
. Use the following methods:ErrorCallback
CancellationCallback
The selfie capturing activity will show the camera to capture image, preview the image, upload image, verify sanity (blurry, too bright, too dark, not white background...), and verify liveness. To start the selfie capturing activity.
TVSelfieConfiguration.Builder builder = new TVSelfieConfiguration.Builder()
.setCameraOption(TVSDKConfiguration.TVCameraOption.FRONT)
.setEnableSound(false)
.requireSanity(true)
.setLivenessMode(TVLivenessMode.PASSIVE);
Options:
TVCameraOption
. Camera modeBool
. Sound should be played or notTVLivenessMode
. Liveness verification modeBool
. Check selfie image sanity or notTrustVisionActivity.startSelfieCapturing(context, builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
}
@Override
public void onCanceled() {
}
});
where:
TVCapturingCallBack
. It is an interface that has 3 methodonSuccess
method has one parameter.TVDetectionResult
. Use the following methods:ErrorCallback
CancellationCallback
The vkyc activity will allow user to capture video, upload selfie image, verify sanity, and checking otp by speech-to-text technology.
TVVkycConfiguration.Builder builder = new TVVkycConfiguration.Builder()
TrustVisionActivity.startVkyc(context, builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
}
@Override
public void onCanceled() {
}
});
where:
context: is the context of the current Activity being displayed
configuration: the configuration would like to pass to self-vkyc activity
callback: is an object of type TVCapturingCallBack
. It is an interface that has 3 method
onSuccess method that will be called in case success. The onSuccess
method has one parameter.
TVDetectionResult
. Use the following methods:onError: ErrorCallback
onCanceled: CancellationCallback
The self-vkyc activity will allow user to capture video, upload selfie image, verify sanity, and checking otp by speech-to-text technology.
TVSelfVkycConfiguration.Builder builder = new TVSelfVkycConfiguration.Builder()
.setCameraOption(TVSDKConfiguration.TVCameraOption.FRONT)
.setEnableSound(false)
.setEnableSanityCheck(true);
Options:
TVCameraOption
. Camera modeBool
. Sound should be played or not.Bool
. The sanity verification should enable or not. (white background check)TrustVisionActivity.startSelfVkyc(context, builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
}
@Override
public void onCanceled() {
}
});
where:
context: is the context of the current Activity being displayed
configuration: the configuration would like to pass to self-vkyc activity
callback: is an object of type TVCapturingCallBack
. It is an interface that has 3 method
onSuccess method that will be called in case success. The onSuccess
method has one parameter.
TVDetectionResult
. Use the following methods:onError: ErrorCallback
onCanceled: CancellationCallback
The face matching does not need an hosted activity, the SDK will send an asynchronous request to server and send back the face-matching response
TrustVisionSDK.faceMatching(imageId1, imageId2, new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
Log.d("", error.getDetailErrorCode() + ":" + error.getDetailErrorDescription();
}
@Override
public void onSuccess(TVDetectionResult result) {
TVCompareFacesResult faceMatchingResult = result.getFaceCompareResult();
// check response
switch faceMatchingResult.getMatchResult() {
case TVCompareFacesResult.MatchResult.MATCHED:
case TVCompareFacesResult.MatchResult.UNSURE:
case TVCompareFacesResult.MatchResult.UNMATCHED:
}
}
@Override
public void onCanceled() {
}
});
where:
TVCapturingCallBack
. It is an interface that has 3 methodonSuccess
method has one parameter.TVDetectionResult
. Use the following methods:ErrorCallback
CancellationCallback
// [FlowStartingFunc]: startTrustVisionSDK, startIdCapturing
TrustVisionActivity.[FlowStartingFunc](..., builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
// ID CARD SANITY RESULT
TVSanityResult idSanity = result.getIdSanityResult();
if (idSanity != null && !idSanity.isGood()) {
String error = idSanity.getError();
switch (error) {
case "image_too_blur":
// Image is too blurry
case "image_too_dark":
// Image is too dark
case "image_too_bright":
// Image is too bright
case "image_has_hole":
// Image has holes
case "image_has_cut":
// Images has been cut
case "image_has_hole_and_cut":
// Images has holes and has been cut
case "photo_not_qualified":
// Image is blurry or not clear
}
}
}
});
// [FlowStartingFunc]: startTrustVisionSDK, startSelfieCapturing
TrustVisionActivity.[FlowStartingFunc](..., builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
}
@Override
public void onSuccess(TVDetectionResult result) {
// PORTRAIT SANITY RESULT
TVSanityResult selfieSanity = result.getSelfieSanityResult()
if (selfieSanity != null && !selfieSanity.isGood()) {
String error = selfieSanity.getError();
switch (error) {
case "image_too_blur":
// Image is too blurry
case "image_too_dark":
// Image is too dark
case "image_too_bright":
// Image is too bright
case "face_too_dark":
// Face is too dark
case "face_too_bright":
// Face is too bright
case "image_has_multiple_faces":
// Image has multiple faces
case "image_has_no_faces":
// Image does not have any face
case "not_white_background": // INDIAN ONLY
// The background is not white enough
case "right":
// Face is looking to the right
case "left":
// Face is looking to the left
case "not_qualified":
// The face is not qualified, could be occluded, covered or having something unusal
case "open_eye,closed_eye":
// Right eye is closed
case "closed_eye,open_eye":
// Left eye is closed
case "open_eye,sunglasses":
// Sunglass covers the right eye
case "sunglasses,open_eye":
// Sunglass covers the left eye
case "closed_eye,closed_eye":
// Both eyes are closed
case "closed_eye,sunglasses":
// Left eye is closed, sunglass covers the right eye
case "sunglasses,closed_eye":
// Sunglass covers the right eye, right eye is closed
case "sunglasses,sunglasses":
// Sunglasses cover both eyes
case "face_too_small":
// Face is too small
case "face_too_big":
// Face is too big
}
}
}
});
// [FlowStartingFunc]: newCameraViewController, startIdCapturing, startSelfieCapturing, faceMatching
TrustVisionActivity.[FlowStartingFunc](..., builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
String message = error.getDetailErrorCode() + ":" + error.getErrorDescription();
Log.d("", message);
showToast(message);
///////////////////////////////////////
// ERROR HANDLER
int code = error.getErrorCode();
String detailErrorCode = error.getDetailErrorCode();
String description = error.getErrorDescription();
switch code {
case TVDetectionError.DETECTION_ERROR_AUTHENTICATION_MISSING:
// Access key or secret is missing. Make sure the SDK is initialized
case TVDetectionError.DETECTION_ERROR_PERMISSION_MISSING:
// No camera permission.
case TVDetectionError.DETECTION_ERROR_CAMERA_ERROR:
// The camera can't be opened.
case TVDetectionError.DETECTION_ERROR_API_ERROR:
// API errors
switch (detailErrorCode.toLowerCase()) {
// connection errors
case "timeout_error":
// Network timeout. Poor internet connection.
case "network_error":
// Network error. No internet connection
// Id card capturing errors
case "nocard_or_multicard_image":
// the input image is no card or multi cards are detected
case "incorrect_card_type": // FOR INDIAN CLIENT ONLY
// the input image is not same type with selected card
case "grayscale_card": // FOR INDIAN CLIENT ONLY
// the input image is grayscale
case "bad_quality_card_image": // FOR INDIAN CLIENT ONLY
// the input image has bad quality
case "incorrect_card_side": // FOR INDIAN CLIENT ONLY
// the input card side is incorrect
// Selfie capturing and face matching errors
case "image_has_no_faces": // while comparing face
// face not detected in selfie image
case "image_has_no_face": // while checking face liveness
// face not detected in selfie image
case "image_has_multiple_faces":
// multiple faces are detected in selfie image
// Common errors
case "access_denied_exception":
// You are not authorized to perform the action.
case "request_time_too_skewed":
// The X-TV-Timestamp header is expired or the current timestamp on device is not correct, need to be updated
case "invalid_parameter_exception":
// Input parameter violates a constraint.
case "image_too_large_exception":
// The input image size exceeds the allowed limit (15MB).
case "invalid_image_format_exception":
// The provided image format is not supported (JPG/PNG)
case "rate_limit_exception":
// The number of requests exceeded your throughput limit.
case "internal_server_error":
// Some unexpected error occurs while processing the request.
}
}
}
@Override
public void onSuccess(TVDetectionResult result) {
}
});
Method | Type | description |
---|---|---|
isLive | Boolean | Determines whether the selfie is live or not |
getScore() | float | The score from 0 to 1 |
Method | Type | description |
---|---|---|
getInfos | List<Info> | List of information are extracted from the ID card |
Info
Method | Type | description |
---|---|---|
getField | String | Name of field example name, address... |
getValue() | String | The value of each field |
Method | Type | description |
---|---|---|
isGood() | Boolean | Determines whether the selfie or id quality is good or not |
getScore() | float | The score from 0 to 1 |
getError() | String | If the quality is not good, the error will be Image too blur , Not white background , Image too bright , Image too dark |
Method | Type | description |
---|---|---|
getMatchResult() | MatchResult | An enum MATCHED , UNMATCHED , UNSURE |
getScore() | float | The score from 0 to 1 |
Method | Type | description |
---|---|---|
getSelfieSanityResult() | TVSanityResult | Result of selfie sanity verification if present |
getLivenessResult() | TVLivenessResult | Result of liveness verification if present |
getFaceCompareResult() | TVCompareFacesResult | Result of face matching if present |
getIdSanityResult() | TVSanityResult | Result of id sanity verification if present |
getCardInfoResult() | TVCardInfoResult | Result of ID extracting if present |
getError() | TVDetectionError | The error found when doing any detection |
For India client only
Method | Type | description |
---|---|---|
getIdFrontImageUrl() | String | Local image url where front id image is stored on disk |
getIdBackImageUrl() | String | Local image url where back id image is stored on disk |
getSelfieImageUrl() | String | Local image url where selfie image is stored on disk |
getIdFrontImageId() | String | Image ID of the front id image got from server after uploaded |
getIdBackImageId() | String | Image ID of the back id image got from server after uploaded |
getSelfieImageId() | String | Image ID of the selfie image got from server after uploaded |
For VKYC only (Coming soon)
Method | Type | description |
---|---|---|
getGpsLocation() | Location | GPS Location where user do self-vkyc |
getIpLocation() | Location | If GPS is not enabled or GPS permission is not granted to the application, use this api to get the location information based on IP address |
getSelfVkycTimestamp() | String | Timestamp at the time user do self-vkyc |
getVkycTimestamp() | String | Timestamp at the time user do vkyc |
getSelfieVideoId() | String | return video id of the uploaded selfie video |
getSelfieVideoUrl() | String | return local URL of the selfie video |
getOtp() | String | Otp generated |
getSpeechToTextOtpResults() | [String] | Array of texts parse from user speech |
getOtpResult() | Bool | True for passed and false for failed. True if the otp value matched one of the speech to text results |
getVkycOverallResult() | Bool | True for approved, False for rejected |
Method | Type | description |
---|---|---|
getDetailErrorCode | String | Error code |
getDetailErrorDescription() | String | Error description |
Method | Type | description |
---|---|---|
getTransactionId() | String | transaction id |
getChannelId() | String | channel id |
Will be called in case failed. Paramters:
TVDetectionError
.Will be called in case the sdk is cancelled. No paramters