5

How to detect that the phone has fingerprint hardware or not. I want a code that detects the fingerprint hardware.

I used this code but this code is showing an error on "isHardwareDetected()" this method.

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 
 }
}
asked May 22, 2021 at 7:48
2
  • 1
    FingerprintManager was deprecated in API level 28, use BiometricPrompt and BiometricManager instead Commented May 22, 2021 at 8:51
  • or use AndroidX Biometric Library Commented May 22, 2021 at 8:53

2 Answers 2

5

I made a minor change in the question code and now it is working fine.

But that class "FingerprintManagerCompat" is deprecated

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
 val manager = FingerprintManagerCompat.from(this)
 if (!manager.isHardwareDetected) {
 Log.e("tag","Fingerprint hardware not detected.")
 } else if (!manager.hasEnrolledFingerprints()) {
 Log.e("tag","No fingerprint is set")
 } else {
 Log.e("tag","Fingerprint is set")
 }
 }
answered May 25, 2021 at 8:35
Sign up to request clarification or add additional context in comments.

2 Comments

This is useful but please mention the alternative for the deprecated class.
Soon I'll update this answer with the alternative classes
1

Add the following code inside AndroidManifest.xml :

<uses-feature android:name="android.hardware.fingerprint" android:required="true" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

Use this where you require to detect the hardware:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
 keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
 fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
 
 if (!fingerprintManager.isHardwareDetected()) {
 Toast.makeText(getApplicationContext(), "Your device doesn't support fingerprint authentication", Toast.LENGTH_SHORT).show();
 }
 if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
 Toast.makeText(getApplicationContext(), "Please enable the fingerprint permission", Toast.LENGTH_SHORT).show();
 
 ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.USE_FINGERPRINT}, FingerprintHandler.FINGERPRINT_PERMISSION);
 
 }
 
 if (!fingerprintManager.hasEnrolledFingerprints()) {
 Toast.makeText(getApplicationContext(), "Your Device has no registered Fingerprints! Please register atleast one in your Device settings", Toast.LENGTH_LONG).show();
 }
}
Abhishek Dutt
1,4527 gold badges18 silver badges27 bronze badges
answered Mar 8, 2022 at 9:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.