Android 中已弃用“canAuthenticate()”

Gan*_* MB 3 java android deprecated

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

医生

此方法已被弃用。使用 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;
    }
Run Code Online (Sandbox Code Playgroud)

使用方法canAuthenticate(int)同上面的方式。

Ste*_*n C 6

代码的直接替换看起来像:

switch (canAuthenticate(Authenticators.BIOMETRIC_WEAK)) {
   case ...
}
Run Code Online (Sandbox Code Playgroud)

根据javadoc,可能的返回值是BIOMETRIC_SUCCESSBIOMETRIC_ERROR_HW_UNAVAILABLEBIOMETRIC_ERROR_NONE_ENROLLEDBIOMETRIC_ERROR_NO_HARDWAREBIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED. ,如前所述。