【问题标题】:'canAuthenticate()' is deprecated in android'canAuthenticate()' 在 android 中已弃用
【发布时间】:2021-07-19 12:42:53
【问题描述】:

我应该使用什么来代替 biometricManager.canAuthenticate() 已被弃用。

Doc

此方法已弃用。 请改用 canAuthenticate(int)。

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

canAuthenticate(int)的使用方法如上。

【问题讨论】:

    标签: java android deprecated


    【解决方案1】:

    您的代码的直接替换如下所示:

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

    根据javadoc,可能的返回值为BIOMETRIC_SUCCESSBIOMETRIC_ERROR_HW_UNAVAILABLEBIOMETRIC_ERROR_NONE_ENROLLEDBIOMETRIC_ERROR_NO_HARDWAREBIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED.,和以前一样。

    【讨论】:

      【解决方案2】:

      canAuthenticate() 上的默认实现已弃用,因为它仅支持 Authenticators.BIOMETRIC_WEAK

      使用以下新实现:

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

      支持以下认证机制:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-21
        • 2012-12-25
        • 2021-08-31
        • 2015-09-18
        • 2018-02-11
        • 2018-03-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多