androidandroid-jetpackandroid-fingerprint-apiandroid-biometric-prompt

Jetpack's BiometricPrompt (androidx.biometric.BiometricPrompt) throws NullPointerException


I'm using androidx.biometric:biometric:1.0.0-alpha03 in a test project and when pushing the negative button I always get the following error message:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence androidx.biometric.BiometricFragment.getNegativeButtonText()' on a null object reference
    at androidx.biometric.BiometricPrompt$1$1.run(BiometricPrompt.java:329)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)

I think this is a library issue which needs to be fixed as the fragment seems to be null or is there anything I'm doing wrong here?

val prompt = BiometricPrompt(activity, Executors.newSingleThreadExecutor(), object : BiometricPrompt.AuthenticationCallback() {
        override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {}
        override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {}
        override fun onAuthenticationFailed() {}
})

val promptInfo = BiometricPrompt.PromptInfo.Builder()
        .setTitle(title)
        .setSubtitle(subtitle)
        .setDescription(description)
        .setNegativeButtonText(activity.getString(android.R.string.cancel))
        .build()

prompt.authenticate(promptInfo)

Solution

  • This was reported three months ago as a bug, and it was reported as fixed two months ago. However, they have not yet released a fresh artifact.

    There are some comments in that issue that suggest that "it's a timing thing", and that adding delays can help as a workaround.