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;
}
READ_PHONE_STATE is one of the Android permissions categorized as dangerous. This is because it “allows read only access to phone state, including the phone number of the device, current cellular network information, the status of any ongoing calls, and a list of any Phone Accounts registered on the device” [2] .
checkSelfPermission(String perm); It returns an integer value of PERMISSION_GRANTED or PERMISSION_DENIED. Note: If a user declines a permission that is critical in the app, then shouldShowRequestPermissionRationale(String permission); is used to describe the user the need for the permission.
android.permission.GET_ACCOUNTS. Allows access to the list of accounts in the Accounts Service. The app uses this permission in an effort to find the device user's name when the support session is presented to a representative.
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.
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.
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!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With