android 生物识别

本文的重点 (The Takeaway From This Article)

Biometric authentication is an extension of fingerprint authentication. A biometric API is far more advanced and straightforward to integrate when compared to its predecessor. In this article, you’re going to learn how to integrate the biometric API and how to use it. Read on to learn about it.

生物特征认证是指纹认证的扩展。 与以前的版本相比,生物识别API更加先进且易于集成。 在本文中,您将学习如何集成生物识别API以及如何使用它。 继续阅读以了解它。

介绍 (Introduction)

In recent years, the Android team’s focus has been mostly on improving security and privacy. Pattern/pin lock has been around for years in Android, and as an enhancement, fingerprint authentication was introduced a couple of years ago. Now it’s time to make enhancements to fingerprint authentication, and that’s known as biometric authentication.

近年来,Android团队的重点主要放在改善安全性和隐私性上。 模式/密码锁在Android中已经存在了多年,并且作为一项增强功能,指纹认证是在几年前引入的。 现在是时候增强指纹身份验证了,这就是所谓的生物特征认证。

Biometric authentication is more secure and easier to use, which comes in handy in many situations, such as authorization for payments, secure and simple login, authentication while accessing sensitive data, and more.

生物特征认证更安全且更易于使用,在许多情况下都很方便,例如付款授权,安全简单的登录,访问敏感数据时进行认证等等。

In addition to that, the biometric API also provides a way to authenticate with a device password or pin without any extra work for developers.

除此之外,生物识别API还提供了一种使用设备密码或密码进行身份验证的方法,而无需开发人员进行任何额外的工作。

检查可用性 (Check Availability)

As I said, the Android security system started with password and pin locks, so some of the devices won’t have the capability of a fingerprint or face unlock. Before enabling this type of authentication for the user, it’s a good practice to check whether the device is compatible with biometric authentication.

就像我说的那样,Android安全系统以密码和密码锁开始,因此某些设备不具备指纹或面部解锁功能。 在为用户启用这种身份验证之前,最好先检查设备是否与生物特征认证兼容。

To check the availability first, we need to get the instance of the system BiometricManager class, as shown below:

要首先检查可用性,我们需要获取系统BiometricManager类的实例,如下所示:

val biometricManager = BiometricManager.from(this)

With the BiometricManager instance, we need to access the canAuthenticate() public function, which results in an integer.

使用BiometricManager 例如,我们需要访问canAuthenticate()公共函数,该函数将产生一个整数。

canAuthenticate() has four possible outcomes:

canAuthenticate()有四个可能的结果:

  • BIOMETRIC_SUCCESS: The device can work with biometric authentication.

    BIOMETRIC_SUCCESS :设备可以使用生物特征认证。

  • BIOMETRIC_ERROR_NO_HARDWARE: No biometric features are available on this device.

    BIOMETRIC_ERROR_NO_HARDWARE :此设备上没有生物特征。

  • BIOMETRIC_ERROR_HW_UNAVAILABLE: Biometric features are currently unavailable in the device.

    BIOMETRIC_ERROR_HW_UNAVAILABLE :设备中当前不提供生物识别功能。

  • BIOMETRIC_ERROR_NONE_ENROLLED: The user hasn’t associated any biometric credentials in the device yet.

    BIOMETRIC_ERROR_NONE_ENROLLED :用户尚未在设备中关联任何生物特征凭证。

Use the Kotlin mighty when to deal with different use cases. Have a look:

when使用Kotlin来应对不同的用例。 看一看:

checking biometric availability
检查生物识别可用性

积分 (Integration)

Biometric library integration is simple. We need to add the following line under the dependencies tag in build.gradle at the app level. Have a look:

生物识别库集成非常简单。 我们需要在应用程序级别的build.gradle中的依赖性标签下添加以下行。 看一看:

dependencies {    implementation 'androidx.biometric:biometric:1.0.1'}

Have a look at the latest version.

看一下最新版本 。

使用生物识别库 (Work With Biometric Library)

This is the exciting part. First, we need to create an instance of an Executor, as shown below:

这是令人兴奋的部分。 首先,我们需要创建一个Executor的实例,如下所示:

val executor = ContextCompat.getMainExecutor(this)

getMainExecutor returns an Executor that runs enqueued tasks on the main thread associated with this context. This is the thread used to dispatch calls to application components (activities, services, etc.). This Executor is used to create a bridge between the biometric services and your application components.

getMainExecutor返回一个Executor ,该执行程序在与此上下文关联的主线程上运行排队的任务。 这是用于将调用分派到应用程序组件(活动,服务等)的线程。 该Executor程序用于在生物识别服务和您的应用程序组件之间建立桥梁。

Next, we need to create an instance of BiometricPrompt, as shown below, to prompt the user with authentication. It has three arguments.

接下来,我们需要创建一个BiometricPrompt实例,如下所示,以提示用户进行身份验证。 它有三个参数。

  1. An instance of the Android component (activity/fragment)Android组件的实例(活动/片段)
  2. An Executor, which we created above

    我们在上面创建的Executor

  3. A lambda expression with three callbacks, known as Biometric.AuthenticationCallback

    具有三个回调的lambda表达式,称为Biometric.AuthenticationCallback

biometric prompt with callbacks
具有回调的生物识别提示

It’s time to post necessary information to the prompt through PromptInfo builder, as shown below:

现在是时候通过PromptInfo将必要的信息发布到提示了 生成器,如下所示:

posting info to biometric to show on UI
将信息发布到生物特征以显示在UI上

All that’s left is to show the biometric dialog using authenticate on the BiometricPrompt instance by passing promptInfo as a parameter.

剩下的就是通过将promptInfo作为参数在BiometricPrompt实例上使用authenticate来显示生物识别对话框。

biometricPrompt.authenticate(promptInfo)

That’s all; the rest of the work will be taken care of by the biometric API and will provide the appropriate result through callbacks.

就这样; 其余的工作将由生物识别API处理,并将通过回调提供适当的结果。

To understand it a bit more clearly, see the following code, where all the pieces are put together:

为了更清楚地理解它,请参阅以下代码,其中所有部分都放在一起:

启用密码选项 (Enable Password Option)

There will be times when your fingerprint option or face detection might have problems. For instance, when there is insufficient light for face detection, it might not work as it’s supposed to. In situations like this, the user should be able to use other modes of authentication, like pin/password/pattern.

有时您的指纹选项或面部检测可能会出现问题。 例如,当光线不足以进行人脸检测时,它可能无法正常工作。 在这种情况下,用户应该能够使用其他身份验证模式,例如密码/密码/模式。

To enable that, the biometric library provides a function setDeviceCredentialAllowed on the BiometricPrompt.PromptInfo instance by passing true as a parameter. Have a look:

为此,生物特征库通过将true作为参数传递来在BiometricPrompt.PromptInfo实例上提供函数setDeviceCredentialAllowed 。 看一看:

奖金 (Bonus)

To learn more about security in Android, read the following article:

要了解有关Android安全性的更多信息,请阅读以下文章:

  • “Secure Communication With the Server From Your Android Client With Certificate Pinning

    “ 通过证书固定从Android客户端与服务器进行安全通信

Thank you for reading.

感谢您的阅读。

翻译自: https://medium.com/better-programming/how-to-set-up-biometric-authentication-in-android-672688afcaae

android 生物识别


http://www.taodudu.cc/news/show-5828747.html

相关文章:

  • 生物特征的种类
  • 用Timeline实现动画特写(下)
  • 耳机特写
  • 人像构图(特写/半身/七分/全身)
  • 服务器 网卡芯片,网卡芯片特写
  • 创建人物特写视频flash教程(一)
  • 一起谈.NET技术,Silverlight 2.5D RPG游戏技巧与特效处理:(七)动画特写
  • 【Fungus笔记】No.4:View(镜头) 特写及处理
  • 创建人物特写视频flash教程(五)
  • opengl对三种光源(方向光,点光源,聚光灯)进行特写并分屏渲染
  • 计算机领域澳大利亚成就,科学网—【编委特写】澳洲Top5科学家:韩清龙 最新成果 - 陈培颖的博文...
  • 作为一个新人,怎样学习嵌入式Linux?被问过太多次,特写这
  • 全栈工程师特写
  • 短视频创作中远、全、近景和特写的意义,懂了才能拍出爆款视频
  • 修理下水道
  • 维修汽车服务器,修车别被坑,老司机2分钟告诉你,修理厂和4S店之间不为人知的秘密!...
  • 修理店修院长的电视机
  • Codeforces Round #462 (Div. 1) A Twisty Movement -12序列的LIS
  • 【许晓笛】EOS 数据库与持久化 API —— 实战
  • UML工具带有数据流程图的客户服务系统案例研究
  • 汽车管理程序(数据结构课程练习)
  • 修车的时候把车子放在维修店里过夜,安全不安全?
  • 排队论简述及LINGO实现(4)——排队论的LINGO实现
  • 医院院长电脑坏了,拿到一个大修理店去修。
  • 如何找到在东湾三谷一个好的汽车车身修理店
  • 生活不易,未来可期
  • csp-202209-2何以包邮?——背包问题
  • (轉貼) 問鼎北市/欣然接受敗選 宋楚瑜告別演說:正式退出政壇 (News)
  • 问题1128:无聊的锤锤
  • Java项目:药品管理系统(java+SpringBoot+html+layui+bootstrap+echarts+mysql)

android 生物识别_如何在android中设置生物特征认证相关推荐

  1. word如何设置上标形式_如何在word中设置特殊页码

    获取更多业界资讯和深度好文● 点击蓝字关注我们 ● 在日常工作中,我们编辑的word文档经常需要设置页码,但有时文档的第一页是封面,第二页才是正文,或者第二页是目录,第三页才是正文,如下图所示,而页码 ...

  2. aws中部署防火墙_如何在AWS中设置自动部署

    aws中部署防火墙 by Harry Sauers 哈里·绍尔斯(Harry Sauers) 如何在AWS中设置自动部署 (How to set up automated deployment in ...

  3. linux中设置环境变量_如何在Linux中设置环境变量

    linux中设置环境变量 Wondering how to set environment variables in Linux? This is exactly what we'll be doin ...

  4. java 千位分隔符_如何在Java中设置千位分隔符?

    问题 如何在Java中设置千位分隔符?我有BigDecimal的String表示,我想设置千位分隔符并返回String. #1 热门回答(180 赞) 你可以使用格式功能","; ...

  5. java中如何设置字体样式_如何在JAVA中设置字体样式和大小?

    我是新来的Java和无法弄清楚如何格式化我的代码是这样的: 字体"宋体"字体大小"9"大胆如何在JAVA中设置字体样式和大小? 我想整个段落的格式化文本.我真的 ...

  6. unity editor android 黑屏_如何在Unity中利用nReal制作AR应用

    来源:新浪VR nReal眼镜是今年最有趣的增强现实小工具之一.它们已经在CES上展示过了,几个月前笔者在北京亲自试用过,在我的评测中,我强调了它们不仅非常轻.时尚,而且还能提供非常明亮的全息视图. ...

  7. android 更改字体_如何在Android中更改字体

    android 更改字体 Ben Stockton 本·斯托克顿 Android offers plenty of options to customize the appearance of you ...

  8. android h 游戏下载地址,Android h游戏_如何在Android手机上玩游戏

    最近人们喜欢在手机上玩游戏. 除了一些手机游戏(Android H游戏)之外安卓才可以玩的h,越来越多的朋友开始寻找Android手机游戏. 但是,有些人已经搜索了很长时间,还没有找到合适的游戏来玩. ...

  9. android 禁用通知栏_如何在Android上禁用通知

    android 禁用通知栏 Notifications are great, and Android's notification system is arguably the best out th ...

最新文章

  1. 归一化互相关Normalization cross correlation (NCC)
  2. 转载:APP的上线和推广——线上推广渠道
  3. android监听器在哪里创建,[转载]android开发中创建按钮事件监听器的几种方法
  4. opencv4版本和3版本_世界名曲鸽子最好听的3个版本,美醉了!
  5. android jni 返回java类
  6. Spring Framework 3.2 M1发布
  7. 探索篇 | 新奇测试策略剖析,大家都觉得多此一举(二)
  8. TensorFlow HOWTO 4.1 多层感知机(分类)
  9. 软件设计师07-程序语言基础知识
  10. 算法 matlab_MATLAB遗传算法及其实现
  11. [转] oracle 数据库 SQL plus 连接方法
  12. [JOYOI1326] 剑人合一
  13. 爬虫笔记_1、爬虫的五个步骤及举例
  14. 人体颈椎神经分布图高清,颈椎神经系统分布图片
  15. 两个excel宏病毒
  16. windows.frames
  17. Python 的一些日常高频写法总结!
  18. scrapy学习笔记——HTML页面解析
  19. TI公司示例下载方式
  20. Mysql 增量备份和全量备份

热门文章

  1. nessus的安装以及使用(带详细步骤)
  2. readdir()函数:读取目录函数
  3. 罗塞塔第一遍以及早期阶段总结博客
  4. 启用新款iMac 2021 的彩色Hello屏幕保护程序!!
  5. 流浪地球2能参与认购吗?电影转让份额合法吗?
  6. 微信支付成功后回调失败
  7. PTA 补充题库 7-18 冒泡法排序
  8. 【贪心】阿里巴巴与四十大盗-背包问题
  9. C++ 用GetAsyncKeyState() 获取所有按键码
  10. 走进计算机科学与技术专业,一期一会丨与南国相会,带你走进计算机科学与技术专业...