Prezado Gabriel, segue a classe MainActivity, XML e as dependências que deve ser informada no build.gradle.
Fazendo dessa forma não tem erro e você poderá abrir seu aplicativo com a digital, pois eu uso esse código em todos meus aplicativos como LOGIN.
package ricciandroid.com.br.biometria;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.an.biometric.BiometricCallback;
import com.an.biometric.BiometricManager;
public class MainActivity extends AppCompatActivity implements BiometricCallback {
private Button button;
BiometricManager mBiometricManager;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.btn_authenticate);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*
*
* */
mBiometricManager = new BiometricManager.BiometricBuilder(MainActivity.this)
.setTitle(getString(R.string.biometric_title))
.setSubtitle(getString(R.string.biometric_subtitle))
.setDescription(getString(R.string.biometric_description))
.setNegativeButtonText(getString(R.string.biometric_negative_button_text))
.build();
//start authentication
mBiometricManager.authenticate(MainActivity.this);
}
});
}
@Override
public void onSdkVersionNotSupported() {
Toast.makeText(getApplicationContext(), getString(R.string.biometric_error_sdk_not_supported), Toast.LENGTH_LONG).show();
}
@Override
public void onBiometricAuthenticationNotSupported() {
Toast.makeText(getApplicationContext(), getString(R.string.biometric_error_hardware_not_supported), Toast.LENGTH_LONG).show();
}
@Override
public void onBiometricAuthenticationNotAvailable() {
Toast.makeText(getApplicationContext(), getString(R.string.biometric_error_fingerprint_not_available), Toast.LENGTH_LONG).show();
}
@Override
public void onBiometricAuthenticationPermissionNotGranted() {
Toast.makeText(getApplicationContext(), getString(R.string.biometric_error_permission_not_granted), Toast.LENGTH_LONG).show();
}
@Override
public void onBiometricAuthenticationInternalError(String error) {
Toast.makeText(getApplicationContext(), error, Toast.LENGTH_LONG).show();
}
@Override
public void onAuthenticationFailed() {
// Toast.makeText(getApplicationContext(), getString(R.string.biometric_failure), Toast.LENGTH_LONG).show();
}
@Override
public void onAuthenticationCancelled() {
Toast.makeText(getApplicationContext(), getString(R.string.biometric_cancelled), Toast.LENGTH_LONG).show();
//mBiometricManager..cancelAuthentication();
}
@Override
public void onAuthenticationSuccessful() {
Toast.makeText(getApplicationContext(), getString(R.string.biometric_success), Toast.LENGTH_LONG).show();
}
@Override
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
// Toast.makeText(getApplicationContext(), helpString, Toast.LENGTH_LONG).show();
}
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
// Toast.makeText(getApplicationContext(), errString, Toast.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn_authenticate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:drawableLeft="@drawable/connect"
android:text="@string/btn_authenticate" />
</RelativeLayout>
NO BUILD.GRADLE INSIRA ESSAS DEPENDÊNCIAS
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation(group: 'com.an.biometric', name: 'biometric-auth', version: '0.1.0', ext: 'aar', classifier: '')
}