TrustVision SDK is the android SDK for TrustVision Engine. This document is for Clients who only use the UI of the SDK. It provides these features:
TrustVisionSDK.init(jsonConfigurationByServer, languageCode);
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
+--2.x.x
+--tv_api_sdk-2.x.x.aar
+--tv_api_sdk-2.x.x.pom
maven-metadata.xml
+--tv_core_sdk
+--tv_sdk
...
build.gradle
repositories {
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" } // from SDK v2.0.0.20 and above
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:2.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.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TrustVisionSDK.init(jsonConfigurationByServer, languageCode);
}
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:
String
. The jsonConfigurationByServer is optional but recommended.
It's the setting specialized for each client from TS server.
It's the response json string get by API https://ekyc.trustingsocial.com/api-reference/customer-api/#get-client-settings.
When it's null or unmatched with the expected type then the default setting in the SDK will be used.String
the code of the language that will show and sound to user. E.g Vietnamese (vi), English (en).TrustVisionSdk.getSupportedLanguages();
TrustVisionSdk.getLanguageCode();
Allow user to change the sdk language after initialization
TrustVisionSdk.changeLanguageCode(String languageCode);
The SDK provides some built in Activities example activity to capture id, selfie, liveness...
The id capturing activity will show the camera to capture image, preview the image. To start the id capturing activity.
TVIDConfiguration.Builder builder = new TVIDConfiguration.Builder()
.setCardType(selectedCard)
.setCardSide(TVSDKConfiguration.TVCardSide.FRONT)
.setReadBothSide(false)
.setEnableSound(false)
.setEnablePhotoGalleryPicker(false)
.setEnableTiltChecking(false)
.setSkipConfirmScreen(false);
TVIDConfiguration configuration = builder.build();
Options:
TVCardType
. List of supported cards can be found by TrustVisionSDK.getCardTypes()
.TVCardSide
. Card side to capture.boolean
. If true then the sdk will capture both side if possible; otherwise, then the card side defined in cardSide will be used.boolean
. Sound should be played or not.boolean
. Allow user select id card image from phone gallery.boolean
. Check if the phone is parallel to the ground before taking the id card photo or not.boolean
. Control whether the SDK should skip the confirmation screen.TrustVisionSDK.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
Use this API https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image The images should be uploaded as JPEG data with 100% quality. For example
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// With front side
result.getFrontCardImage().getImage().compress(Bitmap.CompressFormat.JPEG, 100, stream); // 100% quality
// With back side
result.getBackCardImage().getImage().compress(Bitmap.CompressFormat.JPEG, 100, stream); // 100% quality
// With QR image (Available from v2.0.6.9)
// If result.isRequiredQrImage()` is true then `result.getCardQrImage()` should be non-null. Otherwise, clients should be warned to re-capture id card photos.
result.getCardQrImage().getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, stream); // 100% quality
byte[] dataToUpload = stream.toByteArray();
The selfie capturing activity will show the camera to capture image, preview the image, verify liveness. To start the selfie capturing activity.
TVSelfieConfiguration.Builder builder = new TVSelfieConfiguration.Builder()
.setCameraOption(TVSDKConfiguration.TVCameraOption.FRONT)
.setEnableSound(false)
.setLivenessMode(TVLivenessMode.PASSIVE)
.setSkipConfirmScreen(false);
Options:
TVCameraOption
. Camera modeboolean
. Sound should be played or notTVLivenessMode
. Liveness verification modeboolean
. Control whether the SDK should skip the confirmation screen.TrustVisionSDK.startSelfieCapturing(context, languageCode, 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
Use this api https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image
to get image ids with the inputs are the elements of result.getSelfieImages()
The images should be uploaded as JPEG data with 100% quality. For example:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// With frontal images
result.getSelfieImages().get(index).getFrontalImage().getImage().compress(Bitmap.CompressFormat.JPEG, 100, stream); // 100% quality
// With gesture images
result.getSelfieImages().get(index).getGestureImage().getImage().compress(Bitmap.CompressFormat.JPEG, 100, stream); // 100% quality
byte[] dataToUpload = stream.toByteArray();
Depends on the provided settings, there may be a number of video data (byte array - byte[]
) in the selfie result : result.getSelfieVideos()
With each result.getSelfieVideos()
's element, call the below api to get video id
https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-videoaudioframes
{
"file": " <result.getSelfieVideos().get(index)> "
}
https://ekyc.trustingsocial.com/api-reference/customer-api/#verify-face-liveness Call the above api with below params:
images
field, each element contains:{
"id": "the frontal image id received in step #3.1.3.1 >"
}
gesture_images
field, each element contains:{
"gesture": "lower case string of <result.getSelfieImages().get(i).getGestureType().toGestureType()>",
"images": [
{
"id": "the gesture image id received in step #3.1.3.1 >"
}
]
}
videos
field is a list which comprises 2 lists:[
{
"id": "the video id received in step #3.1.3.2>"
}
]
result.getSelfieFrameLists() // JSONArray
metadata
field isresult.getLivenessMetadata() // JSONObject
// [FlowStartingFunc]: startIdCapturing, startSelfieCapturing
TrustVisionSDK.[FlowStartingFunc](..., builder.build(), new TVCapturingCallBack() {
@Override
public void onError(TVDetectionError error) {
String message = error.getErrorDescription();
Log.d("", message);
showToast(message);
///////////////////////////////////////
// ERROR HANDLER
int code = error.getErrorCode();
String description = error.getErrorDescription();
switch code {
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_SDK_INTERNAL:
// The SDK has an unexpected error.
}
}
@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 |
---|---|---|
getSelfieImages() | List | List of images that each item contains the bitmap of the selfie image |
getSelfieVideos() | List<byte[]> | List of recorded selfie videos |
getSelfieFrameLists() | JSONArray | List of recorded selfie videos frames |
getLivenessMetadata() | JSONObject | Collected data during liveness checking process |
getFrontCardImage() | TVImageClass | Contains bitmap of the front image |
getBackCardImage() | TVImageClass | Contains bitmap of the back image |
getError() | TVDetectionError | The error found when doing any detection |
Method | Type | description |
---|---|---|
getGestureType() | FaceDetectionType | Gesture type of the selfie image |
getFrontalImage() | TVImageClass | Frontal image of the selfie image |
getGestureImage() | TVImageClass | Gesture image of the selfie image |
Method | Type | description |
---|---|---|
getType() | int | Represent a gesture type |
int NEUTRAL = 1
int TURN_LEFT = 5
int TURN_RIGHT = 6
int FACE_UP = 7
int FACE_DOWN = 8
Method | Type | description |
---|---|---|
getLabel() | String | Label of the Image class. |
getImage() | Bitmap | Captured Bitmap |
Method | Type | description |
---|---|---|
getErrorCode() | int | Error code |
getErrorDescription() | String | Error description |
Error code is one of the below list
int TVDetectionError.DETECTION_ERROR_PERMISSION_MISSING = 1004
int TVDetectionError.DETECTION_ERROR_CAMERA_ERROR = 1005
int TVDetectionError.DETECTION_ERROR_SDK_INTERNAL = 1007
Will be called in case failed. Parameters:
TVDetectionError
.Will be called in case the sdk is cancelled. No parameters.