API¶
This section covers the native Android API: how to start the flow, configure the SDK, and implement the available delegates.
Delegate protocols¶
Use these protocols to receive lifecycle callbacks and events:
interface SelfieCaptureListener {
fun onSelfieCaptureStarted()
fun onChallengeTokenRequired()
fun onSelfieCaptureResults(results: SelfieCaptureResult)
fun onSelfieCaptureFinished(error: SelfieCaptureError?)
}
interface SelfieCaptureEventsListener {
fun onSelfieCaptureEvent(event: SelfieCaptureEvent)
}
Starting a flow¶
1) Create a SelfieCaptureConfiguration (build it in code or decode from JSON).
2) Set the events delegate (optional but recommended).
3) Start the SDK with your delegate and configuration.
import androidx.activity.ComponentActivity
import com.veridas.sdk.selfie.entrypoint.SelfieCapture
import com.veridas.sdk.selfie.entrypoint.SelfieCaptureEventsListener
import com.veridas.sdk.selfie.entrypoint.SelfieCaptureListener
import com.veridas.sdk.selfie.error.SelfieCaptureError
import com.veridas.sdk.selfie.event.SelfieCaptureEvent
import com.veridas.sdk.selfie.result.SelfieCaptureResult
class SelfieIntegratorActivity :
ComponentActivity(),
SelfieCaptureListener,
SelfieCaptureEventsListener
{
private companion object {
private val TAG = SelfieIntegratorActivity::class.simpleName
}
fun startCapture() {
SelfieCapture.start(
listener = this,
configuration = getConfigurationFromAsset(fileName),
context = this
)
SelfieCapture.setEventsListener(this)
}
// SelfieCaptureListener
override fun onSelfieCaptureResults(results: SelfieCaptureResult) {
Log.i(TAG, "Selfie SDK -- onSelfieCaptureResults $results")
}
override fun onSelfieCaptureStarted() {
Log.i(TAG, "Selfie SDK -- Started")
}
override fun onChallengeTokenRequired() {
Log.i(TAG, "Selfie SDK -- onChallengeTokenRequired")
val freshChallengeToken = createNewChallengeToken()
SelfieCapture.setChallengeToken(freshChallengeToken)
}
override fun onSelfieCaptureFinished(error: SelfieCaptureError?) {
Log.i(TAG, "Selfie SDK -- onSelfieCaptureFinished $error")
}
// SelfieCaptureEventsListener
override fun onSelfieCaptureEvent(event: SelfieCaptureEvent) {
Log.i(TAG, "Selfie SDK -- onSelfieCaptureEvent $event")
}
}
Example helper for loading JSON configs (shared by all SDKs):
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
@OptIn(ExperimentalSerializationApi::class)
private val json = Json {
ignoreUnknownKeys = true
explicitNulls = false
}
fun getConfigurationFromAsset(fileName: String): SelfieCaptureConfiguration {
val jsonString = applicationContext
.assets
.open(fileName)
.bufferedReader()
.use { it.readText() }
return json.decodeFromString<SelfieCaptureConfiguration>(jsonString)
}
Dispatched events¶
The SDK dispatches a set of events to communicate that the corresponding actions have been taken. Each event is sent to fun onSelfieCaptureEvent(event: SelfieCaptureEvent), which receives a data class:
data class SelfieCaptureEvent
This object contains 2 main attributes, type with the event identifier and detail with all the information related to the event.
| Event Name | Event Detail | Event Trigger |
|---|---|---|
VD_instructions |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When initial instructions are displayed. |
VD_mounted |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the SDK is mounted. |
VD_unmounted |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the SDK is unmounted. |
VD_loaded |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the SDK is fully loaded. |
VD_flowStarted |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the capture flow starts. |
VD_faceNotCentered |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the face is detected as not centered. |
VD_cameraPermissionsGranted |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the user grants camera permissions. |
VD_cameraStarted |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the camera starts successfully. |
VD_cameraVideoPlayStarted |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the camera video playback begins. |
VD_cameraRecorderSetup |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie","width": 960, "height": 1280" |
When the camera recording is configured. |
VD_headOkMovement |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "head", "movementRequested": "top", "challengeNumber": 1 |
When a correct head movement is made. |
VD_headWrongMovementError |
"sdkName": "VD-SELFIE", "type": "error", "flowType": "selfie" |
When an incorrect head movement is detected. |
VD_headMovementTimeoutError |
"sdkName": "VD-SELFIE", "type": "error", "flowType": "selfie" |
When a head movement has not been detected. |
VD_cameraRecorderStop |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the camera recording is stopped. |
VD_successTickFinish |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the success tick animation finishes. |
VD_capture |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie","size": {"height: 1920, "width": 1440"}, "stage": "faceDetection" |
When the final capture completes after success tick. |
VD_capturedSelfie |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the initial selfie is captured before head movements. |
VD_capturedHead |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the head movement process is completed. |
VD_processFinished |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the whole process is finished, either successfully or with an error. |
VD_cameraFailureDefaultError |
"sdkName": "VD-SELFIE", "type": "error", "flowType": "selfie" |
When camera can't be initialised for any reason. |
VD_cameraFailurePermissionError |
"sdkName": "VD-SELFIE", "type": "error", "flowType": "selfie" |
When camera permissions are denied. |
VD_detectionTimeout |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the flow ends due to timeout. |
VD_repeatClicked |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the repeat button is clicked in the review screen. |
VD_closeClicked |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the close button is clicked and user exits from confirmation modal. |
VD_restartClicked |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the restart button is clicked after feedback screen. |
VD_restartProcess |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the process needs to be restarted due to an error. |
VD_restartFromModal |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the process needs to be restarted after help or error modal. |
VD_challengeUpdated |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the challenge token is updated after an error. |
VD_cameraRecorderSetupError |
"sdkName": "VD-SELFIE", "type": "error", "flowType": "selfie" |
When the camera recorder setup fails. |
VD_continueClicked |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the continue button is clicked in review. |
VD_reviewImage |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the review screen is shown. |
VD_loseFocus |
"sdkName": "VD-SELFIE", "type": "info", "flowType": "selfie" |
When the user has lost the focus on the browser tab. |