1

enter image description here

I want to know, the device on which my app running is support fingerprint or not.

But

if(!fingerprintManager!!.isHardwareDetected)
{
 Toast.makeText(context,"Your device doesn't support fingerprint authentication", Toast.LENGTH_SHORT).show()
} 

always return true for any device.

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
Phone Lin
  • 19
  • 2

2 Answers2

0

Ensure that you're using

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

Also

if(ActivityCompat.checkSelfPermission(AppContext, Manifest.permission.USE_BIOMETRIC) == PackageManager.PERMISSION_GRANTED)
{ if (!fingerprintManager!!.isHardwareDetected)
     {  //permission granted but no hardware present
     } else {
        //permission granted and hardware present
} else {
   // Permission not granted }
Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
0

You should migrate from using FingerprintManager to BiometricPrompt. There is a blog that shows just how to do so.

Unlike with the FingerprintManager API, you can check whether a device supports biometric authentication with a single method call: BiometricManager.from(context).canAuthenticate(). This singular method call checks whether there is biometric hardware available on the device, whether the user has enrolled templates, and whether the user has enabled biometric authentication. If all three are not true, then the biometric prompt cannot be shown. It's a highly convenient method that handles all the complexities for you.

// Callback for the "authenticate" button in your app's UI.
override fun onClick(view: View) {
   val promptInfo = createPromptInfo()
   if (BiometricManager.from(context)
               .canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
       biometricPrompt.authenticate(promptInfo, cryptoObject)
   } else {
       loginWithPassword()
   }
}
Isai Damier
  • 976
  • 6
  • 8