8. Listening for Results
Set up a listener to receive the verification result once the SDK verification process is completed.
- In the
onCreate
method of the Fragment from which the sdk was launched, use thelistenForMetricSdkResult
method, which is an extension on theFragment
class to listen for the SDK results.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
listenForMetricSdkResult { outcome ->
when (outcome) {
is VerificationOutcome.Failed -> {
// do something with failed response
val errorText = when (outcome.reason) {
Reason.LIVENESS_FAILED -> "liveness failed"
Reason.CANCELLED -> "cancelled"
Reason.INVALID_TOKEN -> "invalid token"
Reason.VERIFICATION_FAILED -> "verification token"
Reason.UNAUTHORISED -> "unauthorised"
Reason.UNKNOWN -> "unknown"
}
Log.e("TAG", "verification failed $errorText")
}
is VerificationOutcome.Success -> {
Log.e("TAG", "verification succeeded")
}
null -> {
Log.e("TAG", "null received")
}
}
}
}
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.