Interactive biometric verification is recommended for high-risk services like payment.
The static biometric verification service captures faces in real time. It can determine whether a face is of a real person or is a face attack (for example, face recapture image, face recapture video, or face mask) without requiring the user to make specified actions.
This service is widely used in scenarios such as identity verification and mobile phone unlocking.
Currently, the static biometric verification service does not support landscape and split-screen detection.
Interactive biometric verification is recommended for high-risk services like payment.
Before app development, you need to make necessary development preparations, configure the Maven repository address for the HMS Core SDK, and integrate the SDK of this service.
Call Mode | Verification Process | Verification UI | Function |
---|---|---|---|
Default View mode | Processed by ML Kit | Provided by ML Kit | Determines whether a face is of a real person. |
Customized View mode | Processed by ML Kit | Custom | Determines whether a face is of a real person. |
private MLLivenessCapture.Callback callback = new MLLivenessCapture.Callback() { @Override public void onSuccess(MLLivenessCaptureResult result) { // Processing logic when the verification is successful. The verification result indicates whether the face is of a real person. } @Override public void onFailure(int errorCode) { // Processing logic when the verification fails. For example, the camera is abnormal (CAMERA_ERROR). } };
private val callback: MLLivenessCapture.Callback = object : MLLivenessCapture.Callback { override fun onSuccess(result: MLLivenessCaptureResult) { // Processing logic when the verification is successful. The verification result indicates whether the face is of a real person. } override fun onFailure(errorCode: Int) { // Processing logic when the verification fails. For example, the camera is abnormal (CAMERA_ERROR). } }
MLLivenessCapture capture = MLLivenessCapture.getInstance(); capture.startDetect(activity, callback);
val capture = MLLivenessCapture.getInstance() capture.startDetect(activity, callback)
/** *i. Bind the camera preview screen to the remote view and set the liveness detection area. * In the camera preview stream, the static biometric verification service determines whether a face is in the middle of the image. To improve the pass rate, you are advised to place the face frame in the middle of the screen and set the verification area to be slightly larger than the face frame. *ii. Set whether to detect the mask. *ii. Set the result callback. *iii. Load the MLLivenessDetectView to the activity. The sample code is as follows: */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_liveness_custom_detection); mPreviewContainer = findViewById(R.id.surface_layout); //ObtainLLivenessDetectView mlLivenessDetectView = new MLLivenessDetectView.Builder() .setContext(this) // Set whether to perform mask detection. .setOptions(MLLivenessDetectView.DETECT_MASK) // Set the rectangle of the face frame relative to MLLivenessDetectView. .setFaceFrameRect(new Rect(0, 0, 0, 200)) // Set the result callback. .setDetectCallback(new OnMLLivenessDetectCallback() { @Override public void onCompleted(MLLivenessCaptureResult result) { // Callback when the verification is complete. } @Override public void onError(int error) { // Callback when an error occurs during verification. } @Override public void onInfo(int infoCode, Bundle bundle) { // Callback when the verification prompt message is received. // if(infoCode==MLLivenessDetectInfo.NO_FACE_WAS_DETECTED){ // No face is detected. // } // ... } @Override public void onStateChange(int state, Bundle bundle) { // Callback when the verification status changes. // if(state==MLLivenessDetectStates.START_DETECT_FACE){ // Start face detection. // } // ... } }).build(); mPreviewContainer.addView(mlLivenessDetectView); mlLivenessDetectView.onCreate(savedInstanceState); }
override fun onCreate(savedInstanceState: Bundle?) { //super.onCreate(savedInstanceState); //setContentView(R.layout.activity_liveness_custom_detection); //mPreviewContainer = findViewById(R.id.surface_layout); //ObtainLLivenessDetectView mlLivenessDetectView = MLLivenessDetectView.Builder() .setContext(context) // Set whether to perform mask detection. .setOptions(MLLivenessDetectView.DETECT_MASK) // Set the rectangle of the face frame relative to MLLivenessDetectView. .setFaceFrameRect(Rect(0, 0, 0, 200)) // Set the result callback. .setDetectCallback(object : OnMLLivenessDetectCallback { override fun onCompleted(result: MLLivenessCaptureResult) { // Callback when the verification is complete. } override fun onError(error: Int) { // Callback when an error occurs during verification. } override fun onInfo(infoCode: Int, bundle: Bundle) { // Callback when the verification prompt message is received. // if(infoCode==MLLivenessDetectInfo.NO_FACE_WAS_DETECTED){ // No face is detected. // } // ... } override fun onStateChange(state: Int, bundle: Bundle) { // Callback when the verification status changes. // if(state==MLLivenessDetectStates.START_DETECT_FACE){ // Start face detection. // } // ... } }).build() mPreviewContainer.addView(mlLivenessDetectView) with(mlLivenessDetectView) { onCreate(savedInstanceState) } }
@Override protected void onDestroy() { super.onDestroy(); mlLivenessDetectView.onDestroy(); } @Override protected void onPause() { super.onPause(); mlLivenessDetectView.onPause(); } @Override protected void onResume() { super.onResume(); mlLivenessDetectView.onResume(); } @Override protected void onStart() { super.onStart(); mlLivenessDetectView.onStart(); } @Override protected void onStop() { super.onStop(); mlLivenessDetectView.onStop(); }
override fun onDestroy() { super.onDestroy() mlLivenessDetectView.onDestroy() } override fun onPause() { super.onPause() mlLivenessDetectView.onPause() } override fun onResume() { super.onResume() mlLivenessDetectView.onResume() } override fun onStart() { super.onStart() mlLivenessDetectView.onStart() } override fun onStop() { super.onStop() mlLivenessDetectView.onStop() }