How to implement Biometric authentication in your Android App? - complete source code

Описание к видео How to implement Biometric authentication in your Android App? - complete source code

This video shows the steps to implement the Biometric authentication in your Android App.

It uses the androidx.biometric implementation in the App's gradle file for the same. For Biometric authentication, it uses AuthenticationCallback from BiomentricPrompt class from the implemented Biometric libraries in the App's code.

To interpret the results, it simply uses a text view to display the results of the biometric scan whether it succeeded, failed or error.

As the biometric scanner is not available on the emulator, it uses the real device to test the App. The testing of the App on a real phone (device) is shown towards the end of the video.


I hope this video is useful to you. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected]


The complete source code and details of this video is shared in the below link:
https://programmerworld.co/android/ho...

The main Java code is copied below also for reference:

package com.programmerworld.biometricauthenticationapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.concurrent.Executor;

public class MainActivity extends AppCompatActivity {

private TextView textView;
private BiometricPrompt biometricPrompt;
private BiometricPrompt.PromptInfo promptInfo;
private Executor executor;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView = findViewById(R.id.textView);
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);
textView.setText("Error");
}

@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);

textView.setText("Success");
}

@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();

textView.setText("Failure");
}
});

promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Programmer World Authentication")
.setNegativeButtonText("Cancel/ Use Password")
.setConfirmationRequired(false)
.build();
}

public void buttonAuthenticate(View view){
BiometricManager biometricManager = BiometricManager.from(this);
if (biometricManager.canAuthenticate() != BiometricManager.BIOMETRIC_SUCCESS){

textView.setText("Biometric Not Supported");
return;
}
biometricPrompt.authenticate(promptInfo);
}
}

Комментарии

Информация по комментариям в разработке