如何在android中检查指纹认证的设备兼容性 [英] How to check device compatibility for finger print authentication in android

查看:30
本文介绍了如何在android中检查指纹认证的设备兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android 6.0 api 进行指纹认证.我的要求是,如果当前设备支持指纹认证,那么我将通过指纹认证,否则将使用正常方式登录应用程序.

I am working with finger print authentication using android 6.0 api. My requirement is, if current device is supports finger print authentication, then I will go through finger print authentication else will use normal way to login the application.

那么,谁能告诉我,如何在android中检查指纹认证的设备兼容性.

So, any one can tell me, how to check device compatibility for finger print authentication in android.

提前致谢.

推荐答案

您必须在 FingerprintManager 类上使用方法 isHardwareDetected.

You have to use method isHardwareDetected on FingerprintManager class.

确定指纹硬件是否存在且功能正常.退货如果硬件存在且功能正常,则为 true,否则为 false.

Determine if fingerprint hardware is present and functional. Returns true if hardware is present and functional, false otherwise.

// Check if we're running on Android 6.0 (M) or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    //Fingerprint API only available on from Android 6.0 (M)
    FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    if (!fingerprintManager.isHardwareDetected()) { 
        // Device doesn't support fingerprint authentication     
    } else if (!fingerprintManager.hasEnrolledFingerprints()) { 
        // User hasn't enrolled any fingerprints to authenticate with 
    } else { 
        // Everything is ready for fingerprint authentication 
    }
}

别忘了在AndroidManifest中添加访问指纹功能的权限.从 API 28 开始:

Don't forget to add permission to access fingerprint functions in AndroidManifest. Since API 28:

<uses-permission android:name=" android.permission.USE_BIOMETRIC" />

在 API28 之前:

Before API28:

<uses-permission android:name="android.permission.USE_FINGERPRINT" />

使用支持库

如果您不想检查 Build.VERSION,也可以使用支持库在低于 Android 6.0 的设备上检查

If you don't want to check Build.VERSION, it's also possible to check on device lower than Android 6.0 with Support Library

添加依赖:

compile "com.android.support:support-v4:23.0.0"

并使用 FingerprintManagerCompat 类:

FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context);

if (!fingerprintManagerCompat.isHardwareDetected()) { 
    // Device doesn't support fingerprint authentication     
} else if (!fingerprintManagerCompat.hasEnrolledFingerprints()) { 
    // User hasn't enrolled any fingerprints to authenticate with 
} else { 
    // Everything is ready for fingerprint authentication 
}

这篇关于如何在android中检查指纹认证的设备兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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