Skip to main content

Manual Selfie Capture

This module includes a Fragment that allows the user take a selfie with a click of a button. The difference from the Auto Selfie is just there is no button in Auto Selfie as the selfie is taken automatically on AutoSelfie.

Starting the Selfie capture​

Add the imports below:

import ai.amani.sdk.Amani
import ai.amani.sdk.interfaces.IFragmentCallBack
import android.graphics.Bitmap
import java.io.File

Then start the manual selfie capture and get its Fragment as shown below:

// Getting the Fragment view of Selfie
val fragment = Amani.sharedInstance()
.Selfie()
.start(
"XXX_SE_0",
object : IFragmentCallBack {
override fun cb(bitmap: Bitmap?, manualButtonActivated: Boolean?, file: File?) {
// If bitmap is not null, selfie is taken successfully.
// The upload function can be called.
}
}
)

// Navigating to the fragment view
fragment?.let {
replaceFragmentWithBackStack(R.id.frame_manual_selfie, it)
}

Uploading the Captured Selfie​

note

The upload method has to be called after the result of the start method is successful. Otherwise you'll encounter an error in the Errors() object when called.

Add the imports below:

import ai.amani.sdk.Amani

Then upload the captured selfie as shown below:

//Uploading the current taken Selfie data
Amani.sharedInstance()
.Selfie()
.upload(
requireContext(),
"XXX_SE_0"
) { isSuccess ->
if (isSuccess) {
Log.i(TAG, "Selfie is uploaded")
} else {
Log.e(TAG, "Selfie could not be uploaded")
}
}
note

A true result means the document reached the server, not that it was approved. Verification runs asynchronously on the backend, so the outcome arrives later through the event listener rather than here.

Alternatively, if you need the ID of the uploaded document, pass the uploadCallBack { ... } helper instead of the callback above. Everything else stays the same:

import ai.amani.sdk.interfaces.uploadCallBack

Amani.sharedInstance()
.Selfie()
.upload(
requireContext(),
"XXX_SE_0",
uploadCallBack { isSuccess, documentID ->
// isSuccess is true when the document is uploaded
// documentID is the ID of the uploaded document
}
)