这是我在Android P中显示指纹认证提示的代码:
private void displayBiometricPrompt() {
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Fingerprint Authentication cancelled", Toast.LENGTH_LONG);
}
};
BiometricPrompt bm = new BiometricPrompt.Builder(getApplicationContext())
.setTitle("Add a title")
.setSubtitle("Add a subtitle")
.setDescription("Add a description")
.setNegativeButton("CANCEL", getMainExecutor(), onClickListener)
.build();
bm.authenticate(getCancellationSignal(), getMainExecutor(), getAuthenticationCallback());
}
不幸的是它没有工作,因为它没有显示任何对话或提示指纹授权 .
我的代码中也没有错误,我没有任何例外 .
我检查了权限,似乎所有内容都符合生物识别提示的要求 .
没有任何事情发生 .
任何人都可以帮我找出方法吗?
感谢任何帮助
1 回答
你需要检查一些事情才能使用Biometric Prompt:
1-运行Android版本应该是Pie或以上
2-硬件应该可用
3-使用必须在设置中注册至少1个指纹