Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `hasEnrolledFingerprints` giving error that it requires a permission only in my Fragment but not in the Activity in Google's Example?

I am trying to implement the Google's Fingerprint API in my app (in my Fragment specifically). Google has given an example but it's implemented inside an Activity here.

My specific question is that the code below to check if there are enrolled fingerprints already, it is giving me an error (screenshot below):

Question --> What change do I need to do to make it work in my Fragment (as opposed to an activity like Google has)?

if (!mFingerprintManager.hasEnrolledFingerprints()) {
        purchaseButton.setEnabled(false);
        // This happens when no fingerprints are registered.
        Toast.makeText(getActivity(),
                "Go to 'Settings -> Security -> Fingerprint' and register at least one fingerprint",
                Toast.LENGTH_LONG).show();
        return;
    }

enter image description here

like image 833
user1406716 Avatar asked Dec 26 '15 22:12

user1406716


1 Answers

Android 6.0 must 'ask' for permission at run time. https://developer.android.com/training/permissions/requesting.html

Dangerous permissions can give the app access to the user's confidential data. If your app lists a normal permission in its manifest, the system grants the permission automatically. If you list a dangerous permission, the user has to explicitly give approval to your app.

Even if you have <uses-permission android:name="android.permission.USE_FINGERPRINT"/> in your manifest, My understanding is that you must ask for the permission. So it looks like the error is because your app doesn't have -run time- permission to use the fingerprint manager.

(only like 90% sure of this, since I'm sticking with 5.0 for now, sorry)


Update: http://developer.android.com/reference/android/Manifest.permission.html#USE_FINGERPRINT

public static final String USE_FINGERPRINT ---------- Added in API level 23

Allows an app to use fingerprint hardware.

Protection level: normal

So it appears you shouldn't need this permission at run time.

1) Do you have the permission in your manifest?

2) You should put the following code in yours to check to see if permission is revoked/not given for some reason.

if (ContextCompat.checkSelfPermission(thisActivity,
            Manifest.permission.USE_FINGERPRINT) // this might need massaged to 'android.permission.USE_FINGERPRINT'
    != PackageManager.PERMISSION_GRANTED) {
 Log.d ("TEST", "You don't have permission");
 }

(or something close to this) like the example from https://developer.android.com/training/permissions/requesting.html

like image 167
mawalker Avatar answered Nov 15 '22 16:11

mawalker