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:
tv_sdk_client.zip
, extract and put all files into a folder in android project.
Example: folder ${project.rootDir}/repo
Note : tv_sdk_client
Each client will have a SDK name. That SDK name will contain the name of the client
app
root
repo
+--com
+--trustvision
+--tv_api_sdk
+--4.0.x
+--tv_api_sdk-4.0.x.aar
+--tv_api_sdk-4.0.x.pom
maven-metadata.xml
+--tv_core_sdk
+--tv_sdk_client
...
build.gradle
buildscript {
ext.kotlin_version = '1.6.21' // or any version that >= 1.5 and < 1.8
repositories {
maven {
url 'https://maven.google.com'
}
mavenCentral()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
maven { url "path/to/tvsdk/folder" } // example : maven { url "${project.rootDir}/repo" }
...
}
}
Note : If your project uses the new way to define repositories (central declaration of repositories), you must change repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
to repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
repositories {
google()
mavenCentral()
}
}
app/build.gradle
android {
...
aaptOptions {
noCompress "tflite"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('com.trustvision:tv_sdk_client:4.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.
val config = TVInitializeConfiguration(
jsonConfigurationByServer = jsonConfigurationByServer,
endpoint = endpoint,
accessKeyId = accessKeyId,
accessKeySecret = accessKeySecret,
endpointLogger = endpointLogger,
accessKeyIdLogger = accessKeyIdLogger,
accessKeySecretLogger = accessKeySecretLogger,
languageCode = languageCode,
theme = theme,
imageEncryptionKey = imageEncryptionKey,
securityPublicKey = securityPublicKey,
xRequestId = xRequestId,
xRequestId2 = xRequestId2,
flowId = flowId,
enableGetClientSetting = enableGetClientSetting,
tvCertificate = tvCertificate,
headers = headers
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
TrustVisionSDK.init(context, config, object : TVInitializeListener {
override fun onInitSuccess(result: TVInitResult) {
super.onInitSuccess(result)
}
override fun onInitError(error: TVDetectionError) {
}
})
}
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.
Options:
String
the code of the language that will show and sound to user. E.g Vietnamese (vi), English (
en).String
(optional). the key to encrypt image data. It's optional. If it's null or empty then the image data
will not be encrypted.String
(optional). the key to encrypt exif data. It's optional. If it's null or empty then the exif data
will be encrypted by the default key.TVTheme
(optional). The theme of the SDK. If it's null then the sdk will use the default theme or
the theme that we customized for the client.To call the APIs in the SDK, the host app needs to set the following parameters:
String
. The endpoint of the server.String
. The access key id of the server.String
. The secret key of the server.String
(optional) https://ekyc.trustingsocial.com/api-reference/customer-api#api-reconciliationString
(optional)String
(optional). Allow these values:Int
(optional). It is the raw resource ID (@RawRes) of the SSL certificates fileMap<String, String>
(optional). The headers to be added to the request.String
(optional). The flow id of the APIList<Int>
(optional). The list of resource IDs (@RawRes
) corresponds to the SSL certificates that should be added to the request.The host app will call the APIs itself, set the following parameters:
Boolean
(optional).true
(default) for calling api getClientSettings from SDK full mode.false
for otherwise.String
. set this parameter if the host app will call the APIs itself. The jsonConfigurationByServer
is 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.If the log event feature is used, set the following parameters:
String
. The endpoint of the log event server.String
. The access key id of the log event server.String
. The secret key of the log event server.TrustVisionSdk.supportedLanguages
Allow user to change the sdk language after initialization
TrustVisionSdk.changeLanguageCode(languageCode)
wherer:
String
the code of the language that will show and sound to user. E.g Vietnamese (vi), English (
en).Need to have background of Dynamic Feature. Practice guideline reference
Add placeholder placeholder_missing_resources.xml
for missing resources, these values will be override from SDK:
<resources>
<string name="tv_title_activity_main" />
<integer name="google_play_services_version">1</integer>
<style name="tvAppTheme.NoActionBar" parent="AppTheme.NoActionBar" />
</resources>
Please execute this code before starting SDK if we're using Dynamic Feature in host app
TrustVisionSDK.installDynamicFeature {
// We often execute this code to install some necessary resources for dynamic feature
SplitCompat.installActivity(it)
}
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.
val configuration = TVIDConfiguration(
enableSound = true,
cardTypes = selectedCards,
cardSide = TVSDKConfiguration.TVCardSide.FRONT,
isReadBothSide = false,
isEnableScanNfc = true,
isEnableScanQr = true,
isEnablePhotoGalleryPicker = false,
isEnableTiltChecking = false,
isSkipConfirmScreen = true,
isEnableUploadFrames = true,
isEnableUploadImages = true,
isEnableSanityCheck = true,
isEnableDetectIdCardTampering = true,
isEnableReadCardInfo = true,
isEnableCheckNfcData = true,
isEnableVerifyNfc = true
)
Options:
setCardTypes: List<TVCardType>
. Card types is allowed capture.
card_type | description | supported countries |
---|---|---|
TVCardType.default(Country.VIETNAM) | Any of Vietnam national ID versions | vietnam |
TVCardType.cmnd() | Chứng minh nhân dân cũ | vietnam |
TVCardType.cmndNew() | Chứng minh nhân dân mới | vietnam |
TVCardType.cccd() | Căn cước công dân | vietnam |
TVCardType.cccdNew() | Căn cước công dân gắn chip | vietnam |
TVCardType.passport() | Vietnam passport | vietnam |
TVCardType.tcc() | Thẻ căn cước | vietnam |
setEnableSound: boolean
. Sound should be played or not.
setCardSide: TVCardSide
. Card side to capture.
setReadBothSide boolean
. If true then the sdk will capture both side if possible; otherwise, then the card side
defined in cardSide will be used.
setEnableScanNfc boolean
. scan NFC chip of the id card or not.
setEnableScanQr boolean
. scan QR code of the id card or not.
setEnablePhotoGalleryPicker: boolean
. Allow user select id card image from phone gallery.
setEnableTiltChecking: boolean
. Check if the phone is parallel to the ground before taking the id card photo or
not.
setSkipConfirmScreen: boolean
. Control whether the SDK should skip the confirmation screen.
setEnableUploadFrames: boolean
. Enable upload video frames or not. If it's false then the SDK won't call the API to upload
the frames and the APIs that need the video frames will be skipped or called with empty frames data.
setEnableUploadImages: boolean
. Enable upload images or not. If it's false then the SDK won't call the API to upload
the images and the APIs that need the image will be skipped.
setEnableSanityCheck: boolean
. Enable sanity check or not. If it's true then the SDK will call
the API to check the sanity of the id card.
setEnableDetectIdCardTampering: boolean
. Enable ID Tampering Verification or not. If it's true then the SDK
will call the API to
check the tampering of the id card.
setEnableReadCardInfo: boolean
. Enable read card info or not. If it's true then the SDK will call
the API to read the card info.
setEnableCheckNfcData: boolean
. Enable check NFC data or not. If it's true then the SDK will call
the API to get sod and cached fields of the NFC data.
setEnableVerifyNfc: boolean
. Enable verify NFC or not. If it's true then the SDK will call
the API to verify the NFC.
TrustVisionSDK.startIDCapturing(activity, configuration, object : TVCapturingCallBack() {
override fun onNewFrameBatch(frameBatch: FrameBatch) {
}
override fun onError(error: TVDetectionError) {
}
override fun onSuccess(result: TVDetectionResult) {
}
override fun onCanceled(reason: TVCancelReason) {
}
override fun readIdCardImage(image: TVImageClass): TVNfcParams? {
}
})
where:
TVCapturingCallBack
. It is an interface that has 3 methodsNewFrameBatchCallback
. can be called multiple times during the capturing to return frame data.FrameBatch
String
. batch id generated by TV SDKList<TVFrameClass>
. batch frame to pushMap<String, String>
. batch metadata to pushSet<String>
. For debugging purpose onlyonSuccess
method has one parameter.TVDetectionResult
. has the following methods:TVImageClass
TVImageClass
TVCardQr
TVCardQr
TVNfcInfoResult
TVSanityResult
TVSanityResult
TVCardInfoResult
ErrorCallback
. Will be called when an error has occurred during the capturing.TVDetectionError
CancellationCallback
. Will be called when the journey has been cancelled (e.g user clicked on
back button...)TVImageClass
. image of back id cardTVNfcParams
has the following params:String
. The id number of the card. If it's null or empty then the SDK will skip flow scan NFC and continue.String
(optional). The issue date of the cardString
(optional). The hash of the SOD NFCList<String>
(optional). The cached fields of the cardIf the APIs is called by the SDK, please skip this step.
With each batch that returned by onNewFrameBatch(FrameBatch)
callback,
call the below api to upload the data to server, and store the frame batch id that responses from the API, keep it
corresponding with frameBatch.getId()
- local id
https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-frame-batch
For example:
// this dictionary will be used for ID Tampering Verification
val frontCardFrameBatchIdsDictionary: MutableMap<String, String> = mutableMapOf()
val backCardFrameBatchIdsDictionary: MutableMap<String, String> = mutableMapOf()
// frameBatchIdsDictionary.put(
// key = <id_returned_from_sdk>,
// value = <id_responded_from_server>
// )
override fun onNewFrameBatch(frameBatch: FrameBatch) {
val gson = Gson()
val framesStr = gson.toJson(frameBatch.frames)
val params: MutableMap<String, Any> = HashMap()
params["frames"] = framesStr
params["metadata"] = frameBatch.metadata
params["label"] = "video"
val jsonToBeUploaded = gson.toJson(params)
// upload frame batch to server using this api:
// https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-videoaudioframes
val uploadingResult: YourResponseObject = yourMethodToUploadFrameBatch(jsonToBeUploaded)
// Keep the id that generated by the SDK corresponding with the one responded from server
if (cardSide === TVSDKConfiguration.TVCardSide.FRONT) {
frontCardFrameBatchIdsDictionary[frameBatch.id] = uploadingResult.fileId
} else {
backCardFrameBatchIdsDictionary[frameBatch.id] = uploadingResult.fileId
}
}
If the APIs is called by the SDK, please skip this step.
// These lists contain all valid frame batch ids that responded by server
var validFrontCardServerFrameBatchIds: List<String>? = null
var validBackCardServerFrameBatchIds: List<String>? = null
override fun onSuccess(result: TVDetectionResult) {
// the batch id list is null when Frame Recording feature is disabled by client settings.
// Wait until every Frame batch has been uploaded to server before calling this
if (everyFrameBatchUploadingCompleted) {
result.frontCardFrameBatchIds?.also {
validFrontCardServerFrameBatchIds = removeRedundantFrameBatchIds(
frontCardFrameBatchIdsDictionary,
it
)
}
result.backCardFrameBatchIds?.also {
validBackCardServerFrameBatchIds = removeRedundantFrameBatchIds(
backCardFrameBatchIdsDictionary,
it
)
}
}
}
private fun removeRedundantFrameBatchIds(
batchIdsDictionary: MutableMap<String, String>,
validIdsFromSDK: Collection<String>
): List<String> {
val iter: MutableIterator<Map.Entry<String, String>> = batchIdsDictionary.entries.iterator()
while (iter.hasNext()) {
val (key1) = iter.next()
if (!validIdsFromSDK.contains(key1)) {
iter.remove()
}
}
return batchIdsDictionary.values.toList()
}
If the APIs is called by the SDK, please skip the image upload step.
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:
var frontCardId: String? = null
var backCardId: String? = null
var frontQrId: String? = null
var backQrId: String? = null
fun onSuccess(result: TVDetectionResult) {
// With front side
frontCardId = result.frontCardImage?.imageByteArray?.let {
yourMethodToUploadImage(it)
}
// With back side
backCardId = result.backCardImage?.imageByteArray?.let {
yourMethodToUploadImage(it)
}
// In case the QR capturing feature is enabled, and `result.getCardQrImage()` is null then
// the user will be notified, so they can choose to re-capture their ID card.
frontQrId = result.frontIdQr?.images?.getOrNull(i)?.imageByteArray?.let {
yourMethodToUploadImage(it)
}
backQrId = result.backIdQr?.images?.getOrNull(i)?.imageByteArray?.let {
yourMethodToUploadImage(it)
}
}
If the APIs is called by the SDK, please skip this step.
Call this API https://ekyc.trustingsocial.com/api-reference/customer-api/#request-detect-id-card-tampering with params:
{
"image": {
"id": "<frontCardId>"
},
"image2": {
"id": "<backCardId>"
},
"qr1_images": [
{
"id": "<qrId>"
}
],
"card_type": "<result.cardType.getCardId()>",
"videos": [
{
"id": "<validFrontCardServerFrameBatchIds.get(index)>"
},
{
"id": "<validFrontCardServerFrameBatchIds.get(index + 1)>"
},
...
{
"id": "<validBackCardServerFrameBatchIds.get(index)>"
},
{
"id": "<validBackCardServerFrameBatchIds.get(index + 1)>"
},
...
]
}
If the APIs is called by the SDK, please skip this step.
if result.getFrontIdQr().isRequired()
is true then result.getFrontIdQr().getImages()
array should be non-empty. Otherwise, clients should be warned to re-capture id card photos.
QR images will be uploaded with this api: https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image
val frontQrImage = result.frontIdQr?.images?.getOrNull(i)
val metadata: Map<String,String>? = frontQrImage?.metadata
val label: String? = frontQrImage?.label
val data: ByteArray? = frontQrImage?.imageByteArray
*The same logic will be applied to result.getBackIdQr()
If the APIs is called by the SDK, please skip this step.
After capture the back card, if the card has nfc chip, SDK will call readIdCardImage
method in background thread. With image that returned by readIdCardImage
,
call api or do anything to detect id number of the card then return tvNfcParams to start flow scan NFC. If id number is null or empty, SDK skip flow scan NFC and continue
override fun readIdCardImage(image: TVImageClass): TVNfcParams? {
var idNumber: String? = null;
// call api or do any thing to read and return id number
// TODO
return TVNfcParams(idNumber, null, null, null)
}
The selfie capturing activity will show the camera to capture image, preview the image, verify liveness. To start the selfie capturing activity.
val configuration = TVSelfieConfiguration(
cameraOption = TVCameraOption.FRONT,
enableSound = true,
livenessMode = TVLivenessMode.PASSIVE,
isEnableVerticalChecking = false,
isSkipConfirmScreen = true,
isEnableUploadFrames = true,
isEnableUploadImages = true,
isEnableSanityCheck = true,
isEnableVerifyLiveness = true
)
Options:
TVCameraOption
. Camera modeboolean
. Sound should be played or notTVLivenessMode
. Liveness verification modeboolean
. Check if the phone is vertical or not beforeboolean
. Control whether the SDK should skip the confirmation screen.boolean
. Enable upload video frames or not. If it's false then
the SDK won't call the API to upload the frames and the APIs that need the video frames will be skipped or called with empty frames data.boolean
. Enable upload images or not. If it's false then
the SDK won't call the API to upload the images and the APIs that need the image will be skipped.boolean
. Enable sanity check or not. If it's true then the SDK will call
the API to check the sanity of the selfie.boolean
. Enable liveness verification or not. If it's true
then the SDK will call the API to verify the liveness of the selfie.TrustVisionSDK.startSelfieCapturing(activity, configuration, object : TVCapturingCallBack() {
override fun onNewFrameBatch(frameBatch: FrameBatch) {
}
override fun onError(error: TVDetectionError) {
}
override fun onSuccess(result: TVDetectionResult) {
}
override fun onCanceled(reason: TVCancelReason) {
}
})
where:
TVCapturingCallBack
. It is an interface that has 3 methodsNewFrameBatchCallback
. can be called multiple times during the capturing to return frame data.FrameBatch
String
. batch id generated by TV SDKList<TVFrameClass>
. batch frame to pushMap<String, String>
. batch metadata to pushSet<String>
. For debugging purpose onlyonSuccess
method has one parameter.TVDetectionResult
. has the following methods:List<TVImageClass>
List<TVGestureFace>
Collection<String>
JSONObject
ErrorCallback
. Will be called when an error has occurred during the capturing.TVDetectionError
CancellationCallback
. Will be called when the journey has been cancelled (e.g user clicked on
back button...)If the APIs is called by the SDK, please skip this step.
With each batch that returned by onNewFrameBatch(FrameBatch)
callback,
call the below api to upload the data to server, and store the frame batch id that responses from the API, keep it
corresponding with frameBatch.getId()
- local id
https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-frame-batch
For example:
// this dictionary will be used for face liveness Verification
val selfieFrameBatchIdsDictionary: MutableMap<String, String> = mutableMapOf()
// frameBatchIdsDictionary.put(
// key = <id_returned_from_sdk>,
// value = <id_responded_from_server>
// )
override fun onNewFrameBatch(frameBatch: FrameBatch) {
val gson = Gson()
val framesStr = gson.toJson(frameBatch.frames)
val params: MutableMap<String, Any> = HashMap()
params["frames"] = framesStr
params["metadata"] = frameBatch.metadata
params["label"] = "video"
val jsonToBeUploaded = gson.toJson(params)
// upload frame batch to server using this api:
// https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-videoaudioframes
val uploadingResult: YourResponseObject = yourMethodToUploadFrameBatch(jsonToBeUploaded)
// Keep the id that generated by the SDK corresponding with the one responded from server
selfieFrameBatchIdsDictionary[frameBatch.id] = uploadingResult.fileId
}
If the APIs is called by the SDK, please skip this step.
// These lists contain all valid frame batch ids that responded by server
var validServerFrameBatchIds: List<String>? = null
override fun onSuccess(result: TVDetectionResult) {
// the batch id list is null when Frame Recording feature is disabled by client settings.
// Wait until every Frame batch has been uploaded to server before calling this
if (everyFrameBatchUploadingCompleted) {
result.livenessFrameBatchIds?.also {
validServerFrameBatchIds = removeRedundantFrameBatchIds(
selfieFrameBatchIdsDictionary,
it
)
}
}
}
private fun removeRedundantFrameBatchIds(
batchIdsDictionary: MutableMap<String, String>,
validIdsFromSDK: Collection<String>
): List<String> {
val iter: MutableIterator<Map.Entry<String, String>> = batchIdsDictionary.entries.iterator()
while (iter.hasNext()) {
val (key1) = iter.next()
if (!validIdsFromSDK.contains(key1)) {
iter.remove()
}
}
return batchIdsDictionary.values.toList()
}
Use this api https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image to get image ids The images should be uploaded as JPEG data with 100% quality.
For example:
// These lists of image ids will be used in Liveness Verification
val frontalImageIds = mutableListOf<String>()
val gestureImageIds = mutableListOf<String>()
override fun onSuccess(result: TVDetectionResult) {
handleSelfieImages(result.faces, result.gestureFaces)
}
private fun handleSelfieImages(faces: List<TVImageClass>?, gestureFaces: List<TVGestureFace>?) {
faces?.forEach { face ->
// Handle frontal images
face.imageByteArray?.also {
// frontalImageId is the id of the image, returned from server when the uploading API is completed successfully
val frontalImageId = yourUploadImageMethod(it)
frontalImageIds.add(frontalImageId)
}
}
gestureFaces?.forEach { face ->
// Handle gesture images
face.images.forEach { image ->
// gestureImageId is the id of the image, returned from server when the uploading API is completed successfully
val gestureImageId = yourUploadImageMethod(image.imageByteArray ?: return@forEach)
gestureImageIds.add(gestureImageId)
}
}
}
Upload Image API request, parameters:
{
"file": "<byte[] dataToUpload>",
"label": "<proper label, check the API document for detail>"
}
If the APIs is called by the SDK, please skip this step.
API document: https://ekyc.trustingsocial.com/api-reference/customer-api/#verify-face-liveness
Call the above api with below parameters:
images
field{
"images": [
{
"id": "<frontalImageIds.get(index)>"
},
{
"id": "<frontalImageIds.get(index + 1)>"
},
...
]
}
gesture_images
field{
"gesture_images": [
{
"gesture": "<result.getSelfieImages().get(index).getGestureType().toGestureType().toLowerCase()>",
"images": [
{
"id": "<gestureImageIds.get(index)>"
}
]
},
{
"gesture": "<result.getSelfieImages().get(index + 1).getGestureType().toGestureType().toLowerCase()>",
"images": [
{
"id": "<gestureImageIds.get(index + 1)>"
}
]
},
...
]
}
videos
field{
"videos": [
{
"id": "<validServerFrameBatchIds.get(index)>"
},
{
"id": "<validServerFrameBatchIds.get(index + 1)>"
},
...
]
}
metadata
field{
"metadata": "<result.getLivenessMetadata()>"
}
The QR scanner activity will show the camera to scan image, preview the image. To start the QR scanner activity.
val builder = TVQRConfiguration.Builder()
.setCardTypes(cards)
.setCardSide(TVSDKConfiguration.TVCardSide.FRONT)
.setEnableSound(false)
.setSkipConfirmScreen(true)
.setEnableUploadFrames(true)
.setEnableUploadImages(true)
val configuration = builder.build()
Options:
List<TVCardType>
. List of supported cards can be found by TrustVisionSDK.getCardTypes()
if you set jsonConfigurationByServer when init SDK.
If not, use :TVCardType(
"vn.national_id",
"CMND cũ / CMND mới / CCCD",
true,
TVCardType.TVCardOrientation.HORIZONTAL
)
TVCardSide
. Card side to capture.boolean
. Sound should be played or not.boolean
. Control whether the SDK should skip the confirmation screen.boolean
. Enable upload video frames or notboolean
. Enable upload images or notTrustVisionSDK.startQRScanning(activity, configuration, object : TVCapturingCallBack() {
override fun onError(error: TVDetectionError) {
}
override fun onSuccess(result: TVDetectionResult) {
}
override fun onCanceled(reason: TVCancelReason) {
}
})
where:
TVCapturingCallBack
. It is an interface that has 3 methodsonSuccess
method has one parameter.TVDetectionResult
. has the following methods:TVCardQr
TVCardQr
ErrorCallback
. Will be called when an error has occurred during the capturing.TVDetectionError
CancellationCallback
. Will be called when the journey has been cancelled (e.g user clicked on
back button...)If the APIs is called by the SDK, please skip this step.
if result.getFrontIdQr().isRequired()
is true then result.getFrontIdQr().getImages()
array should be non-empty. Otherwise, clients should be warned to re-capture id card photos.
QR images will be uploaded with this api: https://ekyc.trustingsocial.com/api-reference/customer-api/#upload-image
val frontQrImage = result.frontIdQr?.images?.getOrNull(i)
val metadata: Map<String,String>? = frontQrImage?.metadata
val label: String? = frontQrImage?.label
val data: ByteArray? = frontQrImage?.imageByteArray
*The same logic will be applied to result.getBackIdQr()
The NFC scanner activity will show the guideline screen, the scanner popup. To start the NFC scanner activity.
val configuration = TVNfcConfiguration(
nfcCode = nfcCode,
hashSod = sod,
issueDate = issueDate,
cachedFields = cachedFields,
isRequestReadImageNfc = true,
isRequestIntegrityCheckNfc = true,
isRequestCloneDetectionNfc = true,
nfcMaxRetries = 5,
isEnableCheckNfcData = true,
isEnableVerifyNfc = true
)
Options:
String
is the id number of ID cardString
(optional) is the hash of SODString
(optional) is the issue date of ID card (DD/MM/YYYY)List<String>
(optional) is the list of fields that was cached from previous scanningboolean
(optional) read image in the chip when scan nfc or notboolean
(optional) check integrity of the chip when scanning nfc or notboolean
(optional) check clone of the chip when scanning nfc or notInt
. (optional) The maximum number of times the SDK retries an NFC scanning before giving upboolean
. Enable check NFC data or not. If it's true then the SDK will call
the API to get sod and cached fields of the NFC data.boolean
. Enable verify NFC or not. If it's true then the SDK will call
the API to verify the NFC data.TrustVisionSDK.startNfcScanning(activity, configuration, object : TVCapturingCallBack() {
override fun onError(error: TVDetectionError) {
}
override fun onSuccess(result: TVDetectionResult) {
}
override fun onCanceled(reason: TVCancelReason) {
}
})
where:
TVCapturingCallBack
. It is an interface that has 3 methodsonSuccess
method has one parameter.TVDetectionResult
. has the following methods:TVNfcInfoResult
ErrorCallback
. Will be called when an error has occurred during the capturing.TVDetectionError
CancellationCallback
. Will be called when the journey has been cancelled (e.g user clicked on
back button...)The Face Authentication activity will show the guideline screen. To start the Face Authentication activity.
val configuration = TVFaceAuthenticationConfiguration(
cusUserId = "1",
authType = AuthType.AUTH,
authMode = TVAuthMode.FlashEdge(),
isEnableFaceAuthentication = true,
isEnableFaceRegistration = true
)
Options:
String
. The customer user idAuthType
. Type of authentication, AUTH
or REGISTRATION
TVAuthMode
. The source of authentication process, it might be Nfc
or Selfie
boolean
. Enable call API face authentication or notboolean
. Enable call API face registration or notTrustVisionSDK.startFaceAuthentication(activity, configuration, object : TVCapturingCallBack() {
override fun onNewFrameBatch(frameBatch: FrameBatch) {
}
override fun onError(error: TVDetectionError) {
}
override fun onSuccess(result: TVDetectionResult) {
}
override fun onCanceled(reason: TVCancelReason) {
}
})
where:
TVCapturingCallBack
. It is an interface that has 3 methodsNewFrameBatchCallback
. can be called multiple times during the capturing to return frame data.FrameBatch
String
. batch id generated by TV SDKList<TVFrameClass>
. batch frame to pushMap<String, String>
. batch metadata to pushSet<String>
. For debugging purpose onlyonSuccess
method has one parameter.TVDetectionResult
. has the following methods:TVFaceAuthenticationResult
List<TVImageClass>
List<TVGestureFace>
ErrorCallback
. Will be called when an error has occurred during the capturing.TVDetectionError
CancellationCallback
. Will be called when the journey has been cancelled (e.g user clicked on
back button...)Note: Sample code for face authentication in the case of initializing the SDK with the parameters endpoint
, accessKeyId
, and accessKeySecret
.
val configuration = TVFaceAuthenticationConfiguration(
cusUserId = "1",
authType = AuthType.AUTH,
authMode = TVAuthMode.FlashEdge(),
isEnableFaceAuthentication = false,
isEnableFaceRegistration = false
)
TrustVisionSDK.startFaceAuthentication(activity, configuration, object : TVCapturingCallBack() {
override fun onError(error: TVDetectionError) {
}
override fun onSuccess(result: TVDetectionResult) {
val faceIds: List<TVImageClass> = result.faces?.map {
TVSyncFile.createById(it.imageId)
} ?: emptyList()
val gestureFaces: List<TVGestureFace> = result.gestureFaces?.map {
val gesture = it.gesture
val ids = it.images.map { img -> TVSyncFile.createById(img.imageId) }
TVGestureImage(gesture, ids)
} ?: emptyList()
val videoIds = result.livenessFrameBatchIds?.map {
TVVideoFile.createById(it)
}
val cusUserId = "1"
val selfieType = "selfie"
val authType = "transfer"
// SDK uploads images to the server and returns the image IDs to the host app
// call api to verify face authentication
// https://ekyc.trustingsocial.com/api-reference/customer-api#request-face-authentication
yourMethodToCallFaceAuthenticationAPI(
cusUserId,
faceIds,
gestureFaces,
videoIds,
selfieType,
authType
)
}
override fun onCanceled(reason: TVCancelReason) {
}
})
// [FlowStartingFunc]: startIdCapturing, startSelfieCapturing, startQRScanning, startNfcScanning
TrustVisionSDK.[FlowStartingFunc](activity, configuration, object : TVCapturingCallBack() {
override fun onError(error: TVDetectionError) {
val message = error.errorDescription
Log.d("", message)
showToast(message)
///////////////////////////////////////
// ERROR HANDLER
val code = error.errorCode
val description = error.errorDescription
val detailErrorCode = error.detailErrorCode
when (code) {
TVDetectionError.CONFIGURATION_ERROR -> {
// Invalid configuration
}
TVDetectionError.DETECTION_ERROR_PERMISSION_MISSING -> {
// No camera permission.
}
TVDetectionError.DETECTION_ERROR_CAMERA_ERROR -> {
// The camera can't be opened.
}
TVDetectionError.DETECTION_ERROR_SDK_INTERNAL -> {
// The SDK has an unexpected error.
}
TVDetectionError.DETECTION_ERROR_NFC -> {
// The SDK has an unexpected error when scanning NFC
}
TVDetectionError.DETECTION_ERROR_API_ERROR -> {
// The SDK has an unexpected error when calling API
// https://ekyc.trustingsocial.com/api-reference/customer-api#response-errors
}
TVDetectionError.DETECTION_ERROR_MAX_RETRY -> {
// When the SDK reaches the maximum timeout, this only applies to FlashLiveness
}
}
}
override fun onSuccess(result: TVDetectionResult) {
}
override fun onCanceled(reason: TVCancelReason) {
}
})
The SDK provides some built-in API for quick detection
Allow users to quick check if device support NFC so that they can determine for their next step
val isNfcSupport: Boolean = TrustVisionSDK.isNfcSupport(Context)
Allow users to get device information: DeviceInfo
val info: DeviceInfo = TrustVisionSDK.getDeviceInfo(Context)
DeviceInfo
contains following properties (will return empty string if SDK cannot get information of that property)
Property | Type | Description |
---|---|---|
id | String | Device Id |
udid | String | Same as above, Unique Device Id |
sn | String | Serial Number |
imei | String | IMEI |
manufacturer | String | Manufacturer |
deviceName | String | Device name |
wlanMac | String | Wireless mac address |
phoneNumber | String | Current Phone Number |
location | Location | Location information {longitude, latitude} |
Location
contains following properties (will return empty string if SDK cannot get information of that property)
Property | Type |
---|---|
longitude | String |
latitude | String |
Method | Type | description |
---|---|---|
isLive | Boolean | Determines whether the selfie is live or not |
getScore() | float | The score from 0 to 1 |
Method | Type | description |
---|---|---|
getFaces() | List<TVImageClass > | List of images that each item contains the bitmap of the selfie image |
getGestureFaces() | List<TVGestureFace > | List of images that each item contains the bitmap of the selfie image |
getSelfieFrameBatchIds() | Final list of Selfie's local frame batch IDs. Local batch ids that not in this list are invalid and their corresponding server IDs shouldn't be used | |
getLivenessMetadata() | JSONObject | Collected data during liveness checking process |
Method | Type | description |
---|---|---|
getFrontCardImage() | TVImageClass | Contains bitmap of the front image |
getBackCardImage() | TVImageClass | Contains bitmap of the back image |
getQRImage() | TVImageClass | Contains bitmap of the QR image |
getFrontCardFrameBatchIds() | Set<String > | Final list of front side's local frame batch IDs. Local batch ids that not in this list are invalid and their corresponding server IDs shouldn't be used |
getBackCardFrameBatchIds() | Set<String > | Final list of back side's local frame batch IDs. Local batch ids that not in this list are invalid and their corresponding server IDs shouldn't be used |
getNfcInfoResult() | TVNfcInfoResult | Contains info from nfc chip. Use it to call api verify NFC |
Method | Type | description |
---|---|---|
getError() | TVDetectionError | The error found when doing any detection |
Method | Type | description |
---|---|---|
gesture | String | Gesture type of images |
images | List<TVImageClass > | Gesture images |
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 |
getImageByteArray() | byte[] | Captured image as byte array |
getEncryptedHexString() | String | Encrypted image as hex string |
getMetadata() | Map<String, String> | Metadata of the image |
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
Method | Type | description |
---|---|---|
getFrames() | List<TVFrameClass > | Recorded frames during the capturing |
getId() | String | Local ID of the batch, to be corresponds with the ID responded from server after the frame batch is pushed |
getMetadata() | Map<String, String> | Metadata of the batch |
getValidVideoIds() | Set <String > | For debugging purpose only |
Method | Type | description |
---|---|---|
getFramesBase64() | String | The data of the frame as a base64 String |
getIndex() | String | Index of this frame in the list of recorded frames |
getLabel() | String | Label of this frame |
getMetadata() | Map<String, String> | Metadata of this frame |
Will be called in case failed. Parameters:
TVDetectionError
.Will be called in case the sdk is cancelled. No parameters.
Method | Type | Description |
---|---|---|
getCom() | String | |
getSod() | String | |
getDg1() | String | |
getDg2() | String | |
getDg13() | String | |
getDg14() | String | |
getDg15() | String | |
getVerificationResult() | TVNfcVerificationResult |
Method | Type | Description |
---|---|---|
getCloneStatus() | TVNfcVerificationStatus | |
getIntegrityStatus() | TVNfcVerificationStatus | |
getBcaStatus() | TVNfcVerificationStatus |
Method | Type | Description |
---|---|---|
getError() | TVDetectionError | |
getVerdict() | TVNfcVerdict | TVNfcVerdict.NOT_CHECKED TVNfcVerdict.ALERT TVNfcVerdict.GOOD TVNfcVerdict.ERROR |
TVIDConfiguration
] ID Card configurationTVSelfieConfiguration
] Selfie configurationTVLivenessMode
] selfie liveness modeTVAuthMode.Selfie
that using PASSIVE
livenessModeTVAuthMode.Selfie
that using ACTIVE
livenessModeTVAuthMode.Selfie
that using FLASH
livenessModeTVAuthMode.Selfie
that using FLASH_EDGE
livenessModeTVAuthMode.Selfie
that using FLASH_ADVANCED
livenessModeTVAuthMode.Selfie
that using FLASH_8
livenessModeTVAuthMode.Selfie
that using FLASH_16
livenessModeTVAuthMode.Selfie
that using FLASH_32
livenessModeMethod | Type | Description |
---|---|---|
getRequestId() | String | |
getStatus() | String | |
getScore() | Double | |
getMatchResult() | MatchResult | MATCHED, UNMATCHED, UNSURE |
This document introduces how to enable the ability to customize UI components of TrustingVision SDK.
Check out the default UI of TrustingVision SDK. We provide you the ability to change and modify many UI components: background colors, font interfaces, font sizes, icons, buttons.
Initialize and change properties of TVTheme
class. If any of which is not set, it will get default value.
After that, input the instance of TVTheme
as a parameter of the TV SDK's initialization method. See Initialize TV SDK
TVTheme
let you custom and override attributes, which includes:
Properties/Functions | Type | Description |
---|---|---|
idCapturingTheme | TVIdCapturingTheme | Attributes that change the UI of ID Card Detection screen. |
idConfirmationTheme | TVIdConfirmationTheme | Attributes that change the UI of ID Confirmation screen. |
selfieCapturingTheme | TVSelfieCapturingTheme | Attributes that change the UI of Selfie Capturing screen. |
selfieConfirmationTheme | TVSelfieConfirmationTheme | Attributes that change the UI of Selfie Confirmation screen. |
qrGuidelinePopupTheme | TVQrPopupTheme | Modifying UI of QR guideline popup. |
qrRetryPopupTheme | TVQrPopupTheme | Modifying UI of QR retry popup. |
clone() | () -> TVTheme | A function that returns a deep copy of TVTheme 's instance itself. |
Object TVThemeDefaultValues
helps you to quickly change some common UI components that will be used across the whole SDK.
In case a specific Screen's theme is set, it will override TVThemeDefaultValues
's properties.
Properties | Type | Description |
---|---|---|
normalLabelTheme | TVLabelTheme | Normal text of SDK. |
titleLabelTheme | TVLabelTheme | The title of every screen (located on the top-most, centered of screen). |
errorLabelTheme | TVLabelTheme | This text is shown as if any user misconduction or system failure occurred during the detection process. |
instructionLabelTheme | TVLabelTheme | Instruction text. |
timeoutLabelTheme | TVLabelTheme | The count down text. |
The object TVLabelTheme
can be described in this table below:
Properties/Functions | Type | Label's |
---|---|---|
font | Typeface | font family and style |
textSize | Float | text size |
textColor | @ColorInt Int | text color |
textGravity | Int | text alignment of its frame. E.g Gravity.Center, Gravity.Start... |
backgroundColors | [@ColorInt Int] | background colors. If total elements of this array is >= 2, the background color is gradient, else it'd be solid. |
isBackgroundGradientHorizontal | Boolean | background gradient direction |
cornerRadius | Float | rounded corner |
isHidden | Boolean | hide the label |
borderWidth | Float | border width |
borderColor | @ColorInt Int | border color |
clone() | () -> TVLabelTheme | A function that returns a deep copy of TVLabelTheme 's instance itself. |
Here is a snipped code example:
private fun customizeTVCommonThemes() {
// Common Title label theme
val titleLabelThemeDefault = titleLabelTheme
titleLabelThemeDefault.font = your_font
// there are more to be customized...
// Common Normal label theme
val normalLabelThemeDefault = normalLabelTheme
normalLabelThemeDefault.textSize = your_text_size
// there are more to be customized...
// Common Instruction label theme
val instructionLabelTheme = instructionLabelTheme
instructionLabelTheme.textColor = your_text_color
// there are more to be customized...
// Common Error label theme
val errorLabelThemeDefault = errorLabelTheme
errorLabelThemeDefault.cornerRadius = your_corner_radius
// there are more to be customized...
// Common Timeout label theme
val timeoutLabelThemeDefault = timeoutLabelTheme
timeoutLabelThemeDefault.backgroundColors = your_background_colors
// there are more to be customized...
}
Class TVIdCapturingTheme
If a property is not set then the default value will be used.
Properties/Functions | Type | Description |
---|---|---|
titleLabelTheme | TVLabelTheme | See Common UI components section. |
instructionLabelTheme | TVLabelTheme | |
errorLabelTheme | TVLabelTheme | |
timeoutLabelTheme | TVLabelTheme | |
normalLabelTheme | TVLabelTheme | |
qrInstructionLabelTheme | TVLabelTheme | The instruction text that show during QR scanning process. |
closeButtonLocation | enumTVButtonLocation | The position of close button to device orientation: .TOP_LEFT : to the left of the title .TOP_RIGHT : to the right of the title .NONE : hide the button |
showTrademark | Boolean | Show the trademark text or not. |
backgroundColor | @ColorInt Int | Background color of the screen. Default value is black with 60% opacity. |
captureButtonImage | Bitmap | The image of the capture button. |
captureButtonDisableImage | Bitmap | The image of the disabled capture button. |
closeButtonImage | Bitmap | The image of the close view button. |
maskViewNeutralImage | Bitmap | The mask image of camera view when start the ID Capture flow. |
maskViewSuccessImage | Bitmap | The mask image of camera view when detected a valid ID card. |
maskViewErrorImage | Bitmap | The mask image of camera view when cannot detect any ID card. |
qrInstructionBackgroundImage | Bitmap | The image behind the QR instruction text. |
qrMaskViewNeutralImage | Bitmap | The mask image of camera view when start QR detection or not detected any QR code. |
qrMaskViewSuccessImage | Bitmap | The mask image of camera view when detected a valid QR code. |
qrMaskViewErrorImage | Bitmap | The mask image of camera view when detected an invalid QR code. |
loadingImage | Bitmap | Loading indicator in image. |
clone() | () -> TVIdCapturingTheme | A function that returns a deep copy of TVIdCapturingTheme 's instance itself. |
Class TVIdConfirmationTheme
If a property is not set then the default value will be used.
Properties/Functions | Type | Description |
---|---|---|
titleLabelTheme | TVLabelTheme | See Common UI components section. |
errorLabelTheme | TVLabelTheme | |
normalLabelTheme | TVLabelTheme | |
closeButtonLocation | enumTVButtonLocation | The position of close button to device orientation: .TOP_LEFT : to the left of the title .TOP_RIGHT : to the right of the title .NONE : hide the button |
showTrademark | Boolean | Show the trademark text or not. |
backgroundColor | @ColorInt Int | Background color of the screen. Default value is black with 60% opacity. |
closeButtonImage | Bitmap | The image of the close view button. |
confirmButtonImage | Bitmap | The image of the "Look good" button. |
retryButtonImage | Bitmap | The image of the "Try again" button. |
icQrResultSuccessImage | Bitmap | Icon before text that scanned QR successfully. |
icQrResultErrorImage | Bitmap | Icon before text that scanned QR failed. |
maskViewImage | Bitmap | The mask image of camera view showing captured image. |
loadingImage | Bitmap | Loading indicator in image. |
clone() | () -> TVIdConfirmationTheme | A function that returns a deep copy of TVIdConfirmationTheme 's instance itself. |
Class TVSelfieCapturingTheme
If a property is not set then the default value will be used.
Properties/Functions | Type | Description |
---|---|---|
titleLabelTheme | TVLabelTheme | See Common UI components section. |
instructionLabelTheme | TVLabelTheme | |
errorLabelTheme | TVLabelTheme | |
timeoutLabelTheme | TVLabelTheme | |
normalLabelTheme | TVLabelTheme | |
closeButtonLocation | enumTVButtonLocation | The position of close button to device orientation: .TOP_LEFT : to the left of the title .TOP_RIGHT : to the right of the title .NONE : hide the button |
showTrademark | Boolean | Show the trademark text or not. |
backgroundColor | @ColorInt Int | Background color of the screen. Default value is black with 60% opacity. |
captureButtonImage | Bitmap | The image of the capture button. |
captureButtonDisableImage | Bitmap | The image of the disabled capture button. |
closeButtonImage | Bitmap | The image of the close view button. |
switchCameraSideImage | Bitmap | The image of switch camera button. |
maskViewNeutralImage | Bitmap | The mask image of camera view when start the selfie flow. |
maskViewSuccessImage | Bitmap | The mask image of camera view when detected a valid face. |
maskViewErrorImage | Bitmap | The mask image of camera view when cannot detect any valid face. |
progressTheme.isHidden | Boolean | Hide the current 4 steps view. |
progressTheme.backgroundColor | @ColorInt Int | Background color of the circle progress theme. |
progressTheme.progressColor | @ColorInt Int | Background color of the progress steps. |
gestureTheme.isHidden | Boolean | Whether of not should hide selfie steps' group view. |
gestureTheme.turnLeftActiveImage | Bitmap | Image for turn left step gesture when active. |
gestureTheme.turnRightActiveImage | Bitmap | Image for turn right step gesture when active. |
gestureTheme.turnUpActiveImage | Bitmap | Image for turn up step gesture when active. |
gestureTheme.turnDownActiveImage | Bitmap | Image for turn down step gesture when active. |
gestureTheme.lookStraightActiveImage | Bitmap | Image for look straight step gesture when active. |
gestureTheme.turnLeftInactiveImage | Bitmap | Image for turn left step gesture when inactive. |
gestureTheme.turnRightInactiveImage | Bitmap | Image for turn right step gesture when inactive. |
gestureTheme.turnUpInactiveImage | Bitmap | Image for turn up step gesture when inactive. |
gestureTheme.turnDownInactiveImage | Bitmap | Image for turn down step gesture when inactive. |
gestureTheme.lookStraightInactiveImage | Bitmap | Image for look straight step gesture when inactive. |
gestureTheme.finishedGestureBackgroundImage | Bitmap | Background for every step that completed. |
gestureTheme.currentStepFocusImage | Bitmap | Image overlay for current step indicator. |
maskViewErrorImage | Bitmap | The mask image of camera view when cannot detect any valid face. |
maskViewErrorImage | Bitmap | The mask image of camera view when cannot detect any valid face. |
loadingImage | Bitmap | Loading indicator in image. |
clone() | () -> TVSelfieCapturingTheme | A function that returns a deep copy of TVSelfieCapturingTheme 's instance itself. |
Class TVSelfieConfirmationTheme
If a property is not set then the default value will be used.
Properties/Functions | Type | Description |
---|---|---|
titleLabelTheme | TVLabelTheme | See Common UI components section. |
normalLabelTheme | TVLabelTheme | |
closeButtonLocation | enumTVButtonLocation | The position of close button to device orientation: .TOP_LEFT : to the left of the title .TOP_RIGHT : to the right of the title .NONE : hide the button |
showTrademark | Boolean | Show the trademark text or not. |
backgroundColor | @ColorInt Int | Background color of the screen. Default value is black with 60% opacity. |
closeButtonImage | Bitmap | The image of the close view button. |
maskViewImage | Bitmap | The mask image of selfie captured image. |
loadingImage | Bitmap | Loading indicator in image. |
clone() | () -> TVSelfieConfirmationTheme | A function that returns a deep copy of TVSelfieConfirmationTheme 's instance itself. |
Class TVQrPopupTheme
If a property is not set then the default value will be used.
Properties/Functions | Type | Description |
---|---|---|
titleLabelTheme | TVLabelTheme | See Common UI components section. |
descriptionTheme | TVLabelTheme | Theme of description text. |
primaryButtonTheme | TVLabelTheme | Theme of the main button of popup. |
secondaryButtonTheme | TVLabelTheme | Theme of sub-button of popup. |
timeoutLabelTheme | TVLabelTheme | Theme of timeout-warning text. |
backgroundColor | @ColorInt Int | Background color of the view. |
clone() | () -> TVQrPopupTheme | A function that returns a deep copy of TVQrPopupTheme 's instance itself. |
Here is a snipped code example:
private fun initTVTheme(): TVTheme {
val customizedTheme = TVTheme()
// Selfie capturing screen
customizedTheme.selfieCapturingTheme.gestureTheme.lookStraightActiveImage = your_image
// there are more to be customized...
// Selfie confirmation screen
customizedTheme.selfieConfirmationTheme.retryButtonImage = your_image
// there are more to be customized...
// Id capturing screen
customizedTheme.idCapturingTheme.maskViewNeutralImage = your_image
// there are more to be customized...
// Id confirmation screen
customizedTheme.idConfirmationTheme.closeButtonImage = your_image
// there are more to be customized...
// QR guideline popup
customizedTheme.qrGuidelinePopupTheme.headerImage = your_image
// there are more to be customized...
// QR guideline popup
customizedTheme.qrRetryPopupTheme.backgroundColor = your_color
// there are more to be customized...
return customizedTheme
}