API¶
This section covers the native Android API: how to start the flow, configure the SDK, and implement the available delegates.
Listener interfaces¶
Use these interfaces to receive lifecycle callbacks and events:
interface VideoCaptureListener {
fun onVideoCaptureStarted()
fun onVideoCaptureResults(results: VideoCaptureResult)
fun onVideoCaptureFinished(error: VideoCaptureError?)
}
interface VideoCaptureEventsListener {
fun onVideoCaptureEvent(event: VideoCaptureEvent)
}
Starting a flow¶
1) Create a VideoCaptureConfiguration (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.video.entrypoint.VideoCapture
import com.veridas.sdk.video.entrypoint.VideoCaptureEventsListener
import com.veridas.sdk.video.entrypoint.VideoCaptureListener
import com.veridas.sdk.video.error.VideoCaptureError
import com.veridas.sdk.video.event.VideoCaptureEvent
import com.veridas.sdk.video.result.VideoCaptureResult
class VideoIntegratorActivity :
ComponentActivity(),
VideoCaptureListener,
VideoCaptureEventsListener
{
private companion object {
private val TAG = VideoIntegratorActivity::class.simpleName
}
fun startCapture() {
VideoCapture.start(
listener = this,
configuration = getConfigurationFromAsset(fileName),
context = this
)
VideoCapture.setEventsListener(this)
}
// VideoCaptureListener
override fun onVideoCaptureResults(results: VideoCaptureResult) {
Log.i(TAG, "Video SDK -- onVideoCaptureResults $results")
}
override fun onVideoCaptureStarted() {
Log.i(TAG, "Video SDK -- Started")
}
override fun onVideoCaptureFinished(error: VideoCaptureError?) {
Log.i(TAG, "Video SDK -- onVideoCaptureFinished $error")
}
// VideoCaptureEventsListener
override fun onVideoCaptureEvent(event: VideoCaptureEvent) {
Log.i(TAG, "Video SDK -- onVideoCaptureEvent $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): VideoCaptureConfiguration {
val jsonString = applicationContext
.assets
.open(fileName)
.bufferedReader()
.use { it.readText() }
return json.decodeFromString<VideoCaptureConfiguration>(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 onVideoCaptureEvent(event: VideoCaptureEvent), which receives a data class:
data class VideoCaptureEvent
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-VIDEO", "type": "info", "flowType": "video" |
When initial instructions are displayed. |
| VD_mounted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the SDK is mounted. |
| VD_unmounted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the SDK is unmounted. |
| VD_loaded | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the SDK is fully loaded. |
| VD_cameraPermissionsGranted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the user grants camera permissions. |
| VD_cameraStarted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the camera starts successfully. |
| VD_cameraVideoPlayStarted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the camera video playback begins. |
| VD_cameraRecorderSetup | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" "width": 1920, "height": 1080 |
When the camera recording is configured. |
| VD_capturedSelfie | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When face detection is completed. |
| VD_capturedObverse | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the front side of the document is captured. |
| VD_cameraRecorderStop | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the camera recording is stopped. |
| VD_capturedReverse | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the back side of the document is captured. |
| VD_successTickFinish | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the success tick animation finishes. |
| VD_capture | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the video capture is complete. |
| VD_processFinished | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the whole process is finished, either successfully or with an error. |
| VD_cameraFailureDefaultError | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When camera can't be initialised for any reason. |
| VD_cameraFailurePermissionError | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When camera permissions are denied. |
| VD_closeClicked | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the close button is clicked and user exits from confirmation modal. |
| VD_restartProcess | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When the process needs to be restarted due to an error. |
| VD_restartFromModal | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the process needs to be restarted after help modal. |
| VD_restartClicked | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the restart button is clicked after feedback screen. |
| VD_detectionTimeout | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When the flow ends due to timeout. |
| VD_loseFocus | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When the user has lost the focus on the browser tab. |