Skip to content

Android SDK Integration ​

Capturing faces for FaceAuthen with the CAKE eKYC Android SDK, version 1.1.9. The entry point is CakeEkyc.

Build Specifications ​

WhatDescription
Gradle7.4
minSdkVersion21
targetSdkVersion33
Kotlin1.7.10

Add Dependencies ​

groovy
dependencies {
    val core_version = "1.0.0"
    val ui_version = "1.0.2"
    val image_quality_version = "1.0.3"
    val ekyc_version = "1.1.8"

    implementation("vn.cake.ekyc.sdk:ekyc-core:$core_version")
    implementation("vn.cake.ekyc.sdk:ekyc-ui:$ui_version")
    implementation("vn.cake.ekyc.sdk:image-quality:$image_quality_version")
    implementation("vn.cake.ekyc.sdk:ekyc:$ekyc_version")
}

Initialize ​

kotlin
private val logger = object : Logger {
    override fun info(log: String) {}
    override fun error(log: String) {}
    override fun warning(log: String) {}
}

val config = Config.Builder().apply {
    withLanguage("vi")
    withBaseUrl("<BASE_URL>")
    withToken(TokenProvider.from("<ACCESS_TOKEN>"))
    withLogger(logger)
}.build()

val ekycFuture = CakeEkyc.getInstance(applicationContext, config, executor)
val cakeEkyc = ekycFuture.get()

Capture Faces ​

kotlin
val config = TakeFaceConfig(captureOnly = false, loadingView = customLoadingView)

val listener = object : FaceCapturingListener {
    override fun onEvent(event: EkycEvent) {}
    override fun onError(error: EkycError) {}
    override fun onSuccess(result: SelfieResult) {}
}

cakeEkyc.takeFaces(activity, config, listener)

SelfieResult carries the captured faces, the per-image sanityResult, and the livenessResult.

FieldTypeDescription
facesList<Face>?Captured faces, each with image and gesture.
sanityResultList<EkycResponse<FaceSanityData>>?Sanity response per image.
livenessResultEkycResponse<FaceLivenessData>?Liveness result.

Take face.image.id from each entry and pass those as the faces array to Register Faces or Verify Face Authen.

Errors ​

FieldTypeDescription
EkycError.UserCanceledError40001User pressed back.
EkycError.TimeoutError40000Timeout.
EkycError.CameraError40003Opening the camera failed.
EkycError.PermissionNotGranted40002Permissions were not granted.
EkycError.QualityFailed60002 / 60003FACE_SANITY_FAILED or FACE_LIVENESS_FAILED.
EkycError.UnexpectedError50000Runtime exception.

Upload Image ​

When you capture outside the SDK, upload the bytes yourself.

kotlin
val uploadResult = ekyc.upload(image = bitmap, label = "portrait", metaData = metaData)

val imageId = when (uploadResult) {
    is Result.Success -> uploadResult().data?.imageId
    is Result.Fail -> throw uploadResult.error
}

ByteArray is also accepted: ekyc.upload(data = byteArray, label = "portrait", metaData = metaData).

→ Upload Image

Individual Checks ​

Useful when you drive the pipeline yourself rather than calling takeFaces.

kotlin
val faceSanityResult  = ekyc.checkFaceSanity(imageId = "<IMAGE_ID>")
val faceLivenessResult = ekyc.checkLiveness(imageIds = listOf("<IMAGE_ID>"))
val comparedResult     = ekyc.compareFaces(imageId1 = "<IMAGE_ID_1>", imageId2 = "<IMAGE_ID_2>")

compareFaces performs a 1:1 comparison and is independent of FaceAuthen — Verify Face Authen matches against the enrolled profile instead.

Next Steps ​

Developers