棉花糖指纹扫描仪硬件的存在 [英] Marshmallow Fingerprint Scanner Hardware Presence

查看:109
本文介绍了棉花糖指纹扫描仪硬件的存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望开始使用棉花糖指纹认证API。我了解要获得许可,我必须使用以下方法:

I am looking to get started with the Marshmallow Fingerprint Authentication API. I understand that to ask for permission, I must use the following method:

ContextCompat.checkSelfPermission(getContext(), Manifest.permission.USE_FINGERPRINT);

我必须检查设备是否运行的API级别为23或更高。但是,在我征求许可之前,我想先检查一下该设备是否真正具有指纹扫描仪。我发现以下两种方法可以执行此检查:

And I must check if the device is running API level 23 or higher. But before I ask for permission, I would like to check if the device actually has a fingerprint scanner to begin with. I found the following two methods to do this check:

FingerprintManager manager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);

manager.isHardwareDetected();

manager.hasEnrolledFingerprints();

但这两种方法都需要 USE_FINGERPRINT 权限叫了。为什么我要申请使用我不知道的指纹扫描仪的许可?是否还有其他方法可以确定扫描仪是否存在?还是唯一先获得许可的方法?

But both methods require USE_FINGERPRINT permission to be called at all. Why would I want to ask for permission to use a fingerprint scanner that I do not even know exists? Are there any other methods to find out if a scanner exists? Or is the only way to ask for permission first?

推荐答案

我刚刚找到了类 FingerprintManagerCompat ,它确实符合您的期望:

I just found the class FingerprintManagerCompat, which does exactly what you would expect:


一个用于协调对指纹硬件访问的类。

A class that coordinates access to the fingerprint hardware.

在以前的平台上M,此类的行为就像没有可用的指纹硬件一样。

On platforms before M, this class behaves as there would be no fingerprint hardware available.

FingerprintManager中的相同方法不需要 USE_FINGERPRINT 权限,使您可以在请求 USE_FINGERPRINT 之前调用它们

The same methods from FingerprintManager in this class do not require USE_FINGERPRINT permission, enabling you to call them before you ask for USE_FINGERPRINT permission.

FingerprintManagerCompat manager = FingerprintManagerCompat.from(mContext);

manager.isHardwareDetected();
manager.hasEnrolledFingerprints();

这些方法还会在棉花糖预装设备上产生预期的错误结果。

These methods will also yield the expected false results on pre-Marshmallow devices.

这篇关于棉花糖指纹扫描仪硬件的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆