9

I'm trying to implement the fingerprint and not sure if it's an issue but on Android Nougat the permissions for the USE_FINGERPRINT is never asked. So I never get the dialog popup. I have the implementation for ACCESS_FINE_LOCATION and it works (the app ask to allow or deny).

In my manifest:

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

<uses-feature
    android:name="android.hardware.fingerprint"
    android:required="false" />

In the fragment

if (ActivityCompat.checkSelfPermission(getActivity(),Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        Log.v(TAG, "NO permissions USE_FINGERPRINT");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Log.v(TAG, "No requestPermissions");
            ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.USE_FINGERPRINT}, FingerprintHandler.FINGERPRINT_PERMISSION);
        }
        return;
    }
returnvoid
  • 384
  • 6
  • 17

3 Answers3

21

This is normal. The Fingerprint permission is not marked as dangerous and thus you don't have to ask for access to it. It is granted automatically if you declare the permission in your manifest.

This is because you cannot access the sensor directly and all calls to it are proxied trough the FingerprintManager which is somewhat limited.

Edited March 2019: USE_FINGERPRINT is deprecated in favor of USE_BIOMETRIC, but can still be used. USE_BIOMETRIC is granted by declaring it in the manifest as well.

Ch4t4r
  • 1,278
  • 1
  • 10
  • 27
3

It wont ask you to grant permission because of its level of protection (Normal, not dangerous). So access will be automatically granted just by requesting it and without knowledge of the user.

1

follow this steps:

Add this in manifest above permission:

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

you always need permission to access any hardware resources of phone. So it will do that for you.

Then in activity , do following code:

   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();
        }
}

I think it work for you. Thanks!!

Ankit Patidar
  • 2,576
  • 1
  • 12
  • 21