搭建直播带货平台,androidx指纹验证实现的相关代码
androidsdk版本大于29之后,使用FingerprintManagerCompat进行指纹验证显示被废弃,FingerprintManagerCompat的使用方法这里不再叙述。骨骼要求使用新的api去完成指纹验证,当然,BiometricPrompt不仅能做指纹验证,本文只讲解怎么用BiometricPrompt做指纹验证。
官方api:https://developer.android.google.cn/reference/androidx/biometric/package-summary?hl=zh-cn
首先导包
然后它的构造方法
两个构造方法参数基本一致,executor里面是一个runnable接口,在每次进行指纹操作后都会回调这个方法,注意:要想AuthenticationCallback的方法生效,必须在runnable里面执行runnable的run方法。
callback里面有三个回调方法,
1. onAuthenticationError(int errMsgId, CharSequence errString),指纹验证错误会调用此方法,errMsgId的值对应BiometricPrompt里面的常量
2. onAuthenticationSucceeded(@NonNull @NotNull BiometricPrompt.AuthenticationResult result),指纹验证成功后调用,通过result.getAuthenticationType获取验证成功的方式,参数类型自行查看。
3. onAuthenticationFailed() 识别失败调用,具体调用时机不太清楚。。可以参考官方文档说法
显示指纹验证需要一个BiometricPrompt.PromptInfo参数,会弹起一个弹窗进行显示,使用builder的方式初始化,可以设置title,subTitle,description,NegativeButtonText,用法如下
需要注意的是setDeviceCredentialAllowed与setNegativeButtonText只能存在一个,即setNegativeButtonText不为空setDeviceCredentialAllowed必须为false
验证设备是否开启指纹通过BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS方法;
代码展示:
以上就是搭建直播带货平台,androidx指纹验证实现的相关代码, 更多内容欢迎关注之后的文章
原文链接:https://www.cnblogs.com/yunbaomengnan/p/15079365.html