允许在 Marshmallow 以下设备中使用 Android Fingerprint API 构建应用程序

Allow to build Application with Android Fingerprint API in devices below Marshmallow

我有一个使用生物识别技术(指纹 API)的应用程序,让用户登录。现在这个应用程序无法访问没有 Marsh Mallow 设备的用户,但在下面。

当我用 Cipher (API 级别 1) 注释一行时,构建可以 运行 在所有设备中,但是如果没有注释这一行,我只能 运行 它在 Marshmallow 设备中。

我不想要这个解决方案:https://developer.samsung.com/release-note/view.do?v=R000000009

我用过支票:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
    // Initialize the Login Activity that has FingerPrint API
} else {
    // Initialize the second Login Activity that does not have FingerPrint API
}

这是因为某些预读或加载机制,DVM 检测到此 class 在某些方法中具有指纹 API 访问权限。

我说得对吗?还是有其他方法允许登录到 Pre Marsh Mallow 用户?

我通过将 Fingerprint API 相关方法和变量放在一个名为 FingerPrintUtil 的单独 class 中解决了这个问题。现在我可以全局声明这个 class,但只有当 OS 版本高于 Lollipop 时才初始化它。

private FingerPrintUtil fingerprintUtil;

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
    if(fingerprintUtil==null){
fingerprintUtil = new FingerPrintUtil();
}
fingerprintUtil.init();
} else {
    // TODO:change the Ui of the Login Activity to login using EMail/Social login only
}

这样我可以防止验证或 Class 未找到异常。允许 APK 到具有较低版本 Android OS.

的设备