Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

How to check device compatibility for finger print authentication in android

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.

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

Thanks in advance.

question from:https://stackoverflow.com/questions/34409969/how-to-check-device-compatibility-for-finger-print-authentication-in-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to use method isHardwareDetected on FingerprintManager class.

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 
    }
}

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

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

Before API28:

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

With Support Library

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

Add dependency:

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

And use FingerprintManagerCompat class as this:

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 
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...