Android FIngerprint Authentication

 Implement 


implementation 'androidx.biometric:biometric:1.1.0'




BiometricManager biometricManager = BiometricManager.from(this);

switch (biometricManager.canAuthenticate()) {
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
Toast.makeText(getApplicationContext(),"Failed To Authenticate FingerPrint.",Toast.LENGTH_SHORT).show();
break;

case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
Toast.makeText(getApplicationContext(),"Failed To Authenticate FingerPrint.",Toast.LENGTH_SHORT).show();
break;

case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
Toast.makeText(getApplicationContext(),"Failed To Authenticate FingerPrint.",Toast.LENGTH_SHORT).show();
break;
}

Executor executor = ContextCompat.getMainExecutor(this);

biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
Toast.makeText(getApplicationContext(),"Failed To Authenticate FingerPrint.",Toast.LENGTH_SHORT).show();

}

@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
callNewActivity("FingerPrint Authentication Successful.");
}

@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
Toast.makeText(getApplicationContext(),"Failed To Authenticate FingerPrint.",Toast.LENGTH_SHORT).show();

}
});

promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Authenticate FingerPrint")
.setDescription("Use Locked FingerPrint To Login.")
.setNegativeButtonText("Cancel")
.build();


ll_userFingerPrint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
biometricPrompt.authenticate(promptInfo);

}
});

Comments

Popular posts from this blog

How to add layout inflator (Layout Inflators)

Creating RecyclerView and adjusting its margins