Android指纹识别ui显示,Android9.0指纹识别BiometricPrompt的简单使用

谷歌在Android 9.0 API版本28,发布了生物信息综合验证的基础 API

android.hardware.biometrics.BiometricPrompt.BiometricPrompt

所以在android9.0之后使用系统提供的BiometricPrompt来进行指纹识别,BiometricPrompt提供了对话框的构建,方便使用。

首先项目的sdk版本要在28以上

添加权限

代码

private void checkFingerprint() {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

// 构建对话框

BiometricPrompt biometricPrompt = new BiometricPrompt.Builder(this)

.setTitle("指纹验证")

.setDescription("请验证指纹")

.setNegativeButton("取消", getMainExecutor(), new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialogInterface, int i) {

Toast.makeText(MainActivity.this, "取消验证", Toast.LENGTH_SHORT).show();

}

}).build();

// 指纹识别回调

BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricPrompt.AuthenticationCallback() {

@Override

public void onAuthenticationError(int errorCode, CharSequence errString) {

super.onAuthenticationError(errorCode, errString);

Log.i(TAG, "onAuthenticationError: errorCode = " + errorCode + ", errString = " + errString);

}

@Override

public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {

super.onAuthenticationSucceeded(result);

Log.i(TAG, "onAuthenticationSucceeded:");

}

@Override

public void onAuthenticationFailed() {

super.onAuthenticationFailed();

Log.i(TAG, "onAuthenticationFailed:");

}

};

// 开始验证指纹

CancellationSignal cancellationSignal = new CancellationSignal();

biometricPrompt.authenticate(cancellationSignal, getMainExecutor(), authenticationCallback);

}

}

效果

b1cc9b5c29b43f2b02739d8b207bc712.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值