Perform a SmartSelfie Enrollment or Authentication job
SmartSelfie™ Authentication is exposed as a flow which performs the following high level steps:
Displays instructions to the user
Requests camera permissions (if not already granted)
Captures and saves Liveness and Selfie images
Submits the job to the Smile ID API
Delivers the result back to the caller
If you are registering a user for the first time, you should use SmileID.SmartSelfieEnrollment (or SmartSelfieEnrollmentFragment)
If you are authenticating a previously registered user, you should use SmileID.SmartSelfieAuthentication (or SmartSelfieAuthenticationFragment)
import android.util.Logimport androidx.compose.runtime.Composableimport com.smileidentity.SmileIDimport com.smileidentity.compose.SmartSelfieRegistrationimport com.smileidentity.results.SmartSelfieResult@ComposablefunSmartSelfieRegistrationExample() { SmileID.SmartSelfieEnrollment { result ->when (result) {is SmileIDResult.Success -> {val resultData = result.data Log.d("SmartSelfieEnrollment", "Success: $resultData")// SmartSelfieResult.Success contains: captured selfie file, captured liveness // files, and latest job status response from the APIval (selfieFile, livenessFiles, jobStatusResponse) = resultData }is SmileIDResult.Error -> {// There was an error (could be denied camera permissions, network errors, etc)val throwable = result.throwable Log.w("SmartSelfieEnrollment", "Failure: $it", throwable) } } }}
import android.os.Bundleimport android.util.Logimport androidx.fragment.app.FragmentActivityimport com.smileidentity.fragment.SmartSelfieEnrollmentFragmentclassJavaActivity : FragmentActivity() {privatefundoSmartSelfieEnrollment() {val smartSelfieFragment = SmartSelfieEnrollmentFragment.newInstance() supportFragmentManager.setFragmentResultListener( SmartSelfieEnrollmentFragment.KEY_REQUEST,this, ) { _: String?, result: Bundle? ->val smartSelfieResult = SmartSelfieEnrollmentFragment.resultFromBundle(result!!) Log.v("SmartSelfieEnrollment", "Result: $smartSelfieResult")when (smartSelfieResult) {is SmileIDResult.Success -> {val (selfieFile, livenessFiles, jobStatusResponse) = smartSelfieResult.data// Note: Although the API submission is successful, the job status response// may indicate that the job is still in progress or failed. You should// check the job status response to determine the final status of the job.if (jobStatusResponse.jobSuccess) { Log.v("SmartSelfieEnrollment", "Job Success") } elseif (!jobStatusResponse.jobComplete) { Log.v("SmartSelfieEnrollment", "Job Not Complete") } else { Log.v("SmartSelfieEnrollment", "Job Failed") } }is SmileIDResult.Error -> {val throwable = smartSelfieResult.throwable Log.v("SmartSelfieEnrollment", "Error: "+ throwable.message) } } supportFragmentManager .beginTransaction() .remove(smartSelfieFragment) .commit() } supportFragmentManager .beginTransaction() .replace(android.R.id.content, smartSelfieFragment) .commit() }}
When using the Fragment approach, a convenience resultFromBundle static method is provided to help extract a typed object from the result Bundle.
Arguments
The Javadocs also contain detailed information regarding each parameter.
userId
The user ID to associate with the SmartSelfie™ Registration. Most often, this will correspond to a unique User ID within your own system. (If not provided at time of Registration, a random user ID will be generated. This field is required for Authentication)
jobId
The job ID to associate with the SmartSelfie™ Registration. Most often, this will correspond to a unique Job ID within your own system. If not provided, a random job ID will be generated.
allowAgentMode
Whether to allow Agent Mode or not. If allowed, a switch will be displayed allowing toggling between the back camera and front camera. If not allowed, only the front camera will be used.
showAttribution
Whether to show the Smile ID attribution or not on the Instructions screen
extraPartnerParams
Custom values specific to partners passed as an immutable map
Callback to be invoked when the SmartSelfie™ Registration is complete. The result itself is a SmileIDResult which can either be a SmileIDResult.Success or SmileIDResult.Error