如何在Android中使用KeyGenerator为FingerPrint API生成密钥

我正在尝试为我的应用程序实现FingerPrint API.为此,我正在关注Google的 Fingerprint Dialog sample.

如果compileSdkVersion = 23和minSdkVersion = 23,它的工作正常,但我的应用程序的compileSdkVersion是21,minSdkVersion是14.为此,我使用FingerprintManagerCompat而不是FingerprintManager,它工作正常,但问题在于密钥生成.

android.security.keystore.KeyGenParameterSpec;
android.security.keystore.KeyPermanentlyInvalidatedException;
android.security.keystore.KeyProperties;

密钥库包及其类不可用于生成密钥,18个API版本中提供密钥生成的所有支持算法,任何人都可以指导我如何生成密钥以支持更低版本,请?

解决方法

看看FingerprintManagerCompat javadoc:

A class that coordinates access to the fingerprint hardware.

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

看一下源代码

final int version = Build.VERSION.SDK_INT;
if (version >= 23) {
   // a working implementation
   IMPL = new Api23FingerprintManagerCompatImpl();
} else {
   // an empty stub
   IMPL = new LegacyFingerprintManagerCompatImpl();
}

如果您的设备低于API VERSION 23,则使用LegacyFingerprintManagerCompatImpl,这只是一个STUB.例如:

@Override
public boolean hasEnrolledFingerprints(Context context) {
   return false;
}
@Override
public boolean isHardwareDetected(Context context) {
   return false;
}

您不能在旧设备中使用此功能.那些API(一些来自android.security.keystore)仅在Android M上可用

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...