SoFunction
Updated on 2025-04-05

Android adds fingerprint unlocking function implementation code

Preface

Fingerprint unlocking technology has become an important means to verify user information. Basically, all mobile phones are equipped with fingerprint unlocking. When the developed APP requires encryption verification, you can consider adding the system fingerprint unlocking function.

The steps to add fingerprint unlocking function are very simple, the general process is as follows:

1 Add permissions

Add permission to access user's fingerprint in the file.

 <uses-permission android:name=".USE_FINGERPRINT"/>

2 Declare the fingerprint management object provided by the system

private FingerprintManagerCompat manager;

3 Obtain fingerprint management object

 manager = (this);

4 Perform the verification process

 (null, 0, null, new FingerAuthenticateCallBack(), null);

5 Monitor fingerprint verification results

The fingerprint verification result is passed to the developer through a callback, and the developer needs to inherit the AuthenticationCallback class. The specific methods are as follows:

 public class FingerAuthenticateCallBack extends  {
  private static final String TAG = "FingerAuthenticateCallBack";
  // Call back this function when an error occurs, such as when multiple attempts fail, errString is an error message  @Override
  public void onAuthenticationError(int errMsgId, CharSequence errString) {
   (TAG, "onAuthenticationError: " + errString);
  }
  // This function will be called back when fingerprint verification fails. After failure, multiple attempts are allowed. Too many failures will stop responding for a period of time and then stop the sensor's work  @Override
  public void onAuthenticationFailed() {
   (TAG, "onAuthenticationFailed: " + "Verification failed");
  }
  @Override
  public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
   (TAG, "onAuthenticationHelp: " + helpString);
  }
  // This function will be called back when the verified fingerprint is successful, and then the fingerprint sensor will no longer be monitored  @Override
  public void onAuthenticationSucceeded(
              result) {
   (TAG, "onAuthenticationSucceeded: " + "Verification Successfully");
  }
 }

Summarize

The above is the implementation code for adding fingerprint unlocking function to Android introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!