7. Listening for Results
Set up a listener to receive the verification result once the SDK verification process is completed.
In the nActivityResult
callback method of your current activity, use the following code to listen for SDK results:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
...
if (requestCode == METRIC_SDK_REQUEST_CODE) {
val result = Metric.getResultsFromIntent(data) ?: return
when (result) {
is VerificationOutcome.Failed -> {
// do something with failed response
val errorText = when (result.reason) {
Reason.LIVENESS_FAILED -> "LIVENESS_FAILED"
Reason.CANCELLED -> "CANCELLED"
Reason.INVALID_TOKEN -> "INVALID_TOKEN"
Reason.VERIFICATION_FAILED -> "VERIFICATION_FAILED"
Reason.UNAUTHORISED -> "UNAUTHORISED"
Reason.UNKNOWN -> "UNKNOWN"
Reason.LOCATION_SERVICE_UNAVAILABLE -> "LOCATION_UNAVAILABLE"
Reason.LOCATION_PERMISSION_DENIED ->"LOCATION_PERMISSION_DENIED"
Reason.CAMERA_PERMISSION_DENIED -> "CAMERA_PERMISSION_DENIED"
}
Log.e("TAG", "Verification failed $errorText")
}
is VerificationOutcome.Success -> {
Log.e("TAG", "Verification successful")
}
}
}
...
}
info
For an updated approach, or if you are working within fragments or other components that are neither activities nor fragments, consider using the new ActivityResultContracts or the ActivityResultRegistry APIs, depending on your use case. You can find an example of the ActivityResultsContract implementation in the example project linked here.
In this code:
- The result is then analyzed using a
when
statement to handle different outcome states. You can take appropriate actions based on the verification result.