'canAuthenticate()' is deprecated in android

Viewed 2112

What should I use instead of biometricManager.canAuthenticate() is deprecated.

Doc says

This method is deprecated. Use canAuthenticate(int) instead.

    BiometricManager biometricManager = BiometricManager.from(this);
    switch (biometricManager.canAuthenticate()){
        case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
            break;
        case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
            break;
        case BiometricManager.BIOMETRIC_SUCCESS:
            break;
        case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
            break;
        case BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED:
            break;
    }

How to use canAuthenticate(int) like the above manner.

2 Answers

The direct replacement for your code would look something like:

switch (canAuthenticate(Authenticators.BIOMETRIC_WEAK)) {
   case ...
}

According to the javadoc, the possible return values are BIOMETRIC_SUCCESS, BIOMETRIC_ERROR_HW_UNAVAILABLE, BIOMETRIC_ERROR_NONE_ENROLLED, BIOMETRIC_ERROR_NO_HARDWARE, or BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED., as before.

The default implementation on canAuthenticate() is deprecated as it supported only Authenticators.BIOMETRIC_WEAK

With the following new implementation :

BiometricManager.from(context).canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK)

Following authentication mechanisms are supported :

public interface Authenticators {
        /**
         * Any biometric (e.g. fingerprint, iris, or face) on the device that meets or exceeds the
         * requirements for <strong>Class 3</strong> (formerly <strong>Strong</strong>), as defined
         * by the Android CDD.
         */
        int BIOMETRIC_STRONG = 0x000F;

        /**
         * Any biometric (e.g. fingerprint, iris, or face) on the device that meets or exceeds the
         * requirements for <strong>Class 2</strong> (formerly <strong>Weak</strong>), as defined by
         * the Android CDD.
         *
         * <p>Note that this is a superset of {@link #BIOMETRIC_STRONG} and is defined such that
         * {@code BIOMETRIC_STRONG | BIOMETRIC_WEAK == BIOMETRIC_WEAK}.
         */
        int BIOMETRIC_WEAK = 0x00FF;

        /**
         * The non-biometric credential used to secure the device (i.e. PIN, pattern, or password).
         * This should typically only be used in combination with a biometric auth type, such as
         * {@link #BIOMETRIC_WEAK}.
         */
        int DEVICE_CREDENTIAL = 1 << 15;
    }
Related