Skip to main content

Auto Selfie Capture

Auto Selfie Capture provides you with an UI Fragment configurations that allow the user's selfie to be taken automatically. In this module, if the selfie cannot be taken after the given time, it offers a way to capture the selfie with a press of a button. The main difference between the Auto Selfie Capture and Manual Selfie Capture is it provides a real-time tracking of faces on the screen while checking the face is in the desired dimensions and distance.

caution

In order to use this module, the noCompress option for tflite files must be set as shown below. Otherwise you'll get a compile errors.

aaptOptions {
noCompress "tflite"
}
Flow overviewFlowchart of this module's usage within the SDK flow. Expand to view it, click the chart to enlarge.

Auto Selfie Capture flow

  • A1: configure in Application.onCreate with DynamicFeature.SELFIE_AUTO.
  • A2, A3: set the event listener with AmaniEvent().setListener(...), then start the session.
  • A4: AutoSelfieCapture().start(...); show the returned fragment (null means: check onError); set timeOutManualButton in ASCBuilder before start(). No bitmap yet means the user has not captured yet; the module stays open. After the timeout set with ASCBuilder(timeOutManualButton = ...), the user can capture with the manual button. If there is still no capture, count 20–30 seconds on your side after the button appears and handle the process as you need.
  • A5: upload the selfie. A successful upload goes on, the verdict arrives later. If the upload fails or the step is REJECTED, do not call upload() again: the data is cleared after it. Open the selfie again (a new fragment, or the old one with your own fragment handling, e.g. popBackStack), capture, then upload, up to your own max attempt.
  • A6, A7: follow the verdicts in stepsResult / profileStatus, and call finishSession() at the end.
  • Other modules may come before or after the selfie, in the order your flow needs; the chart shows the selfie alone to keep it simple.

Starting the Capture​

↑ Flow step A4

User Interface Settings​

Before calling the start() method, you can adjust some settings related to Auto Selfie Capture fragment. To do this, use the ASCBuilder class.

Add the imports below:

import ai.amani.sdk.modules.selfie.auto_capture.ASCBuilder

Then configure the Auto Selfie UI as shown below:

// preparing the user interface.
val ascBuilder = ASCBuilder(
R.color.color_black, // Text color of message
20, // Text size of message
R.color.any_color, // Text color of counter animation.
true, // Counter visibility as boo
100, // Counter text size (It should be proportional to the screen size. As a proper usage: getScreenHeight()/10)
20, // Manual capture button time out as second.
"Be sure to be close enough", // Message texts
"Face not found", // Message texts
"Hold stable, while taking photo", // Message texts
"Failed, process will restart in 3 seconds", // Message texts
R.color.any_color2, // Oval view color
R.color.any_color3) // Success animate color

Getting the fragment​

Now you can call the actual start() method with the ASCBuilder you've just created.

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 auto selfie capture and get its Fragment as shown below:

val fragment = Amani.sharedInstance()
.AutoSelfieCapture()
.start(
docType = "type_of_document: XXX_SE_0",
ascBuilder = ascBuilder,
frameLayout = frameLayout,
object : IFragmentCallBack {
override fun cb(bitmap: Bitmap?, manualButtonActivated: Boolean?, file: File?) {
// Capture is successfull if bitmap is not null
}
}
)

// navigating the created fragment view
fragment?.let {
replaceFragmentWithBackStack(R.id.frame_auto_selfie, it)
}

Uploading the Captured Selfie​

↑ Flow step A5

caution

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

Add the imports below:

import ai.amani.sdk.Amani
import ai.amani.sdk.interfaces.IUploadCallBack

Then upload the captured selfie as shown below:

//Uploading the current taken Selfie data
Amani.sharedInstance()
.AutoSelfieCapture()
.upload(
requireContext(),
"type_of_document example: XXX_SE_0",
object : IUploadCallBack{
override fun cb(
isSuccess: Boolean
) {
//isSuccess means the Selfie Data is uploaded
//result is the result of uploaded document it should be equal "OK"
// if the current Selfie has no error
//If Selfie has errors, errors object will not be null anymore
}
}
)

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()
.AutoSelfieCapture()
.upload(
requireContext(),
"type_of_document example: XXX_SE_0",
uploadCallBack { isSuccess, documentID ->
// isSuccess is true when the document is uploaded
// documentID is the ID of the uploaded document
}
)