Good afternoon Devs!
I'm playing with biometric authentication on Android, but I'm having trouble asking the user to use biometrics authentication, although I have declared in Manifest.xml, I can not make the request via UI so that the user allows and I can call the dialog which will authenticate and in the settings of the app installed on my device shows that it needs this permission.
How do I request permission like this for the user?
Manifest.xml <uses-permission android:name="android.permission.USE_BIOMETRIC" />
clicking on the button to authenticate I call this method and if it would be the one responsible for verifying the permission and requesting it if necessary:
//iniciando o biometricPrompt
public void authenticationUser(View view){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_BIOMETRIC) != PackageManager.PERMISSION_GRANTED){
//solicitando permissão para o usuário para utilizar a biometria
ActivityCompat.requestPermissions(BiometricDemoActivity.this, new String[] {Manifest.permission.USE_BIOMETRIC},
MY_PERMISSIONS_REQUEST_USE_BIOMETRIC);
return;
}
BiometricPrompt mBiometricPrompt = new BiometricPrompt.Builder(this)
.setTitle("Demo Autenticação por Biometria")
.setSubtitle("É necessário a autenticação para prosseguir")
.setDescription("Esse aplicativo usa autenticação por biometria para proteger os seus dados")
.setNegativeButton("Cancel", this.getMainExecutor(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
notifyUser("Autenticção cancelada");
}
}).build();
mBiometricPrompt.authenticate(getCanceledSignal(), getMainExecutor(), getAuthenticationCallback());
}