Android BiometricPrompt DeviceCredentialHandler : onCreate: Executor and/or callback was null

标签 android react-native android-biometric-prompt

看起来像BiometricPrompt 1.0.0 有一个错误,它会保持在不可见状态并抛出该异常

我会在答案中建议解决方法

编辑(感谢@Isai Damier):

重现方式:

  1. 打开生物识别提示
  2. 按后退按钮 - 关闭提示
  3. 再次按返回并退出应用
  4. 返回应用 - 尝试再次打开提示

最佳答案

此修复是在生物识别提示版本为 1.0.0 时引入的。这个问题在 1.0.1 中不会重现

//-------------------------------------------------------- ----------------------------

我想出了一个解决方法 - 在用户取消时在提示上调用“cancelAuthentication”。

完整代码如下(在 react native 应用程序中使用 - 这就是 promise 的原因):

    private const val E_BIOMETRIC_ERR = "E_FINGER_PRINT_ERR"
    private const val OPENED = "success"
    private var bp: BiometricPrompt? = null
    private var mAuthenticationPromise: Promise? = null

    fun authenticate(activity: AppCompatActivity, title: String,
                     subTitle: String, description: String, authenticationPromise: Promise) {
        mAuthenticationPromise = authenticationPromise

        val executor = Executors.newSingleThreadExecutor()

        bp?.cancelAuthentication()
        bp = getBiometricPrompt(activity, executor)

        val promptInfo = BiometricPrompt.PromptInfo.Builder()
                .setTitle(title)
                .setSubtitle(subTitle)
                .setDescription(description)
                .setDeviceCredentialAllowed(true)
                .build()

        bp!!.authenticate(promptInfo)

    }



    private fun getBiometricPrompt(activity: AppCompatActivity, executor: Executor): BiometricPrompt {
        return BiometricPrompt(activity, executor, object : BiometricPrompt.AuthenticationCallback() {

            override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
                super.onAuthenticationSucceeded(result)
                mAuthenticationPromise?.resolve(OPENED)
            }

            override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
                super.onAuthenticationError(errorCode, errString)
                bp!!.cancelAuthentication()
            }

            override fun onAuthenticationFailed() {
                super.onAuthenticationFailed()
                bp!!.cancelAuthentication()
            }
        })
    }

我希望它对任何人都有帮助 - 干杯

关于Android BiometricPrompt DeviceCredentialHandler : onCreate: Executor and/or callback was null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58846672/

相关文章:

java - LibGdx 拉伸(stretch)/变形像素(例如在像素艺术中)

android - 如何强制更新 expo 应用程序

react-native - 如何在 react native 的固定尺寸 View 中适应任何尺寸的图像

android - BiometricPrompt : Why should we check KeyguardManager. isDeviceSecure() 在启用 setDeviceCredentialAllowed 之前?

Android - BiometricPrompt 检测是否是面部识别码或触摸识别码

Android 在将 androidx 生物识别更新为 1.0.0-alpha04 后崩溃

java - 无法解析构造函数 jsonobjectrequest

java - 尝试按标签获取 View 时 Android 崩溃

android - 后退按钮后重新加载数据库值

react-native - 如何检测 native react 中的催化剂模式?