androidx生物特征提示中的三处失败尝试后关闭提示?

时间:2020-02-10 06:33:15

标签: android androidx android-biometric-prompt

我在我的应用程序中使用了androidX生物识别提示。因为我有三个查询,

  1. 在计数了三次失败尝试之后,是否有任何选项可以关闭提示。

  2. 是否有任何选项可以显示密码屏幕,而无需单击“使用密码”按钮(如果启用的设备凭据为true)。

    password screen

  3. 是否可以自定义提示框。

1 个答案:

答案 0 :(得分:2)

  1. 5次尝试失败后,提示自动关闭。 不过,您可以覆盖BiometricCallback并覆盖“ onAuthenticationFailed”以计算失败次数

     override fun onAuthenticationFailed() {
            super.onAuthenticationFailed()
            //You can count the number of failed attempts, and call the cancellation signal here, onAuthenticationError will not be called if you do
     }
    
    override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
            super.onAuthenticationError(errorCode, errString)
            //explains to you in the errString why the authentication failed after *five* attempts
    
     }
    
  2. 我不确定,但是我认为如果您显示提示且启用了凭据,则用户在提示上会有一个按钮“使用密码”

   * The user will first be prompted to authenticate with biometrics, but also given the
   * option to authenticate with their device PIN, pattern, or password. Developers should
   * first check {@link KeyguardManager#isDeviceSecure()} before enabling this. If the device
   * is not secure, {@link BiometricPrompt#BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL} will be
   * returned in {@link AuthenticationCallback#onAuthenticationError(int, CharSequence)}}.
   * Defaults to false.
   *
   * Note that {@link #setNegativeButton(CharSequence, Executor,
   * DialogInterface.OnClickListener)} should not be set if this is set to true.
   *
   * @param allowed When true, the prompt will fall back to ask for the user's device
   *               credentials (PIN, pattern, or password).
   * @return
   */
  @NonNull public Builder setDeviceCredentialAllowed(boolean allowed) {
      mBundle.putBoolean(KEY_ALLOW_DEVICE_CREDENTIAL, allowed);
      return this;
  }

3. only the text on it

val prompt =
            BiometricPrompt.Builder(context).setTitle(title).setSubtitle(subtitleText).setDescription(description)
                .setNegativeButton(negativeButton, executor!!, cancelListener).build()