FragmentManager уже выполняет транзакции при выполнении biometricPrompt? .Authenticate (promptInfo) внутри фрагмента - PullRequest
2 голосов
/ 01 мая 2019

Если вы создаете biometricPrompt и promptInfo в упражнении, оно работает нормально. Но мне не удается заставить его работать внутри фрагмента.

Это внутри фрагмента, и он вызывается внутри OnViewCreated. Вы делаете то же самое в действии, оно прекрасно работает, 1 решением было бы передать biometricPrompt и PromptInfo из действия и передать его внутрь фрагмента.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    tryToDisplayBiometricPrompt()
}


@TargetApi(Build.VERSION_CODES.M)
private fun tryToDisplayBiometricPrompt() {
    //Create a thread pool with a single thread
    biometricPrompt = BiometricPrompt(activity as FragmentActivity, Executors.newSingleThreadExecutor(), object : BiometricPrompt.AuthenticationCallback() {
        override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
            super.onAuthenticationSucceeded(result)
            authenticationSuccessful()
        }

        override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
            super.onAuthenticationError(errorCode, errString)
            if (errorCode == BiometricConstants.ERROR_NEGATIVE_BUTTON || errorCode == BiometricConstants.ERROR_USER_CANCELED || errorCode == BiometricPrompt.ERROR_CANCELED) return
            authenticationlistener?.isBiometricAvailable = false
            authenticationlistener?.onAuthenticationFailed()
        }
    })

    promptInfo = BiometricPrompt.PromptInfo.Builder()
            .setTitle(getString(R.string.biometric_title))
            .setSubtitle(getString(R.string.biometric_subtitle))
            .setDescription(getString(R.string.biometric_description))
            .setNegativeButtonText(getString(R.string.cancel))
            .build()

    biometricPrompt?.authenticate(promptInfo)
}
...