-1

How can I check if a device has a fingerprint sensor, and if it does not, how can I show that it does not?

I have this code and it works well on cellphones that don't have a fingerprint sensor, but does not work on fingerprint sensor phones. The text continues to show that the phone has no fingerprint. How can I fix this?

FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(getApplicationContext());
if (!fingerprintManagerCompat.isHardwareDetected()) {
    // O dispositivo não suporta a autenticação de impressão digital
    BtnActionFingerprint.setEnabled(false);
    BtnActionFingerprint.setText(R.string.button_title_fingerprint_not_supported);
} else
    if (!fingerprintManagerCompat.hasEnrolledFingerprints()) {
        // O usuário não registrou nenhuma impressão digital para autenticar com
        BtnActionFingerprint.setEnabled(false);
        BtnActionFingerprint.setText(R.string.button_title_fingerprint_supported_but_unavaliable);
    } else {
        // Tudo está pronto para a autenticação de impressão digital 
        BtnActionFingerprint.setEnabled(true);
        BtnActionFingerprint.setText(R.string.button_title_fingerprint_supported);
    }
Alexandre Justino
  • 1,716
  • 1
  • 19
  • 28
  • Hope [this](https://stackoverflow.com/questions/34409969/how-to-check-device-compatibility-for-finger-print-authentication-in-android) will help you to solve your problem. – Naveed Akhtar Oct 26 '17 at 13:14
  • Possible duplicate of [How to check device compatibility for finger print authentication in android](https://stackoverflow.com/questions/34409969/how-to-check-device-compatibility-for-finger-print-authentication-in-android) – manish Feb 04 '19 at 08:48

2 Answers2

1

Simply you achieve by doing this:

 try {
      Button btn=(Button)findViewbyId(R.id.btn);
        FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(MainActivity.this);
        if (!fingerprintManagerCompat.isHardwareDetected()) {
            // Device doesn't support fingerprint authentication
            Toast.makeText(this, "device not support", Toast.LENGTH_SHORT).show();
            btn.setText("Device not supported");
        } else if (!fingerprintManagerCompat.hasEnrolledFingerprints()) {
            // User hasn't enrolled any fingerprints to authenticate with
            Toast.makeText(this, "not enrolled", Toast.LENGTH_SHORT).show();
            btn.setText("Device not Enrolled");
        } else {
            Toast.makeText(this, "ready to use fingerPrint", Toast.LENGTH_SHORT).show();
            // Everything is ready for fingerprint authentication
         btn.setText("Ready to use fingerprint");
        }
    }catch (Exception e){
        e.printStackTrace();
        Log.e("130",">>>"+e+"<<<<<");
    }

  • Here is a screenshot which clears your all doubts

Screenshot of code running on Samsung On8 and OnNext. Toast shows negative on first and OK on second

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
Vishal Yadav
  • 1,020
  • 4
  • 15
  • 30
  • In my works this method, but I wanted to use the message on a Button, taking out the Toast. Can you do that? along with the strings predefined within the strings.xml – Micahel Keller Oct 26 '17 at 21:05
0

Maybe you miss permission in Manifest:

<uses-permission
    android:name="android.permission.USE_FINGERPRINT" />
LaurentY
  • 7,495
  • 3
  • 37
  • 55