GBG Developers

Guides   |   Using the Liveness Service

Using the Liveness Service

The Liveness service automatically prompts the user to face the camera and perform actions such as looking in a different direction, or smiling. After a number of actions, the SDK responds with a result indicating the liveness status.

The service can be used either by using the SDK’s LivenessActivity, or by using a LivenessFragment.

For the first method, start the activity as shown here. Liveness cannot be the first service used; a person identifier, customer reference and document verification identifier are needed from a previous document verification.

 

val REQUEST_LIVENESS = 1003
val personId = "96a44cc0-1159-417e-b2f0-4dce1aa3a75e"
val customerRef = "96a44cc0-1159-417e-b2f0-4dce1aa3a75e"
val documentId = "8a4acb7-ae48-9551-8e51-cdf92da30221"
val livenessIntent = LivenessActivity.getLivenessIntent(this@MainActivity, personId, customerRef, documentId)
startActivityForResult(livenessIntent, REQUEST_LIVENESS)

 

Handle the returned result as shown in the example code snippet below.

 

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == REQUEST_LIVENESS && resultCode == RESULT_OK) {               val result = data?.getParcelableExtra<LivenessResultResponse>(KEY_LIVENESS_RESULT_RESPONSE)
        val scannerError = data?.getParcelableExtra<com.gbg.verify.liveness.ScannerError>(KEY_LIVENESS_ERROR)
        val serviceError = data?.getStringExtra(KEY_LIVENESS_SERVICE_ERROR)
        Log.d(TAG, "got liveness result: $result")
    }
}

 

When the code is run, the camera will start up and a message and animated graphic will appear, to prepare the user.


After the user has proceeded to continue with the Liveness detection, further prompts and animated graphics will appear to guide the user to perform the physical liveness actions.


Another way of using the Liveness service is by embedding a fragment provided by the SDK.

Here’s some example code to do that:

val livenessConfig = Configuration()        
LivenessFragment.newInstance( personId , custRef, docId, livenessConfig, livenessListener =
    object : VerifyLivenessListener{
        override fun onAggregatedResult (result: AggregatedResult, resultResponse: LivenessResultResponse? ) {
        }
        override fun onActionEventAudit (audit: ActionResultState ) {
        }
        override fun onNewImage (bitmap: Bitmap ) {
        }
        override fun onError(livenessError: ErrorResponse) {
        }
        override fun onError(livenessError: com.gbg.verify.liveness.ScannerError) {
        }
    }
)

When run, the onAggregatedResult function can be used to extract parameters such as the finalResult which contains an enumeration for the liveness result with values including Failed, Passed or Interrupted.