How to identify if device has in-display Biometric fingerprint support?

元气小坏坏 提交于 2019-12-04 11:30:47

问题


I'm writing a application feature to authenticate user using Biometric fingerprint authentication API. And it worked as expected with combination of BiometricPrompt API.

In general it display own UI dialog so it can be unified across Android device.(Improvement from Fingerprint Manager API)

In one of device testing scenario I come across in-display(on screen, e.g. Oneplus 6T device) fingerprint support instead rear biometric hardware option.

When I run application on it, on call of biometricPrompt.authenticate(..) instead of dialog it display in-display fingerprint authentication option. Which is ok, and manage by internal API of BiometricPrompt.

But it create some inconsistency to manage for developer.

  1. When it provide in-build authentication dialog, all fallback error displayed in dialog itself.
  2. But in case of in-display authentication I didn't found a way where it manage to display error message it-self. And I have to handle this fallback and display in a custom way.

Now question is

  1. Is there a way to manage/display message by in-display authentication view component.
  2. How can identify if device is support in-device biometric authentication.

Edit: Code reference I'm using:

import android.content.Context
import androidx.biometric.BiometricPrompt
import androidx.fragment.app.FragmentActivity
import java.lang.Exception
import java.util.concurrent.Executors
import javax.crypto.Cipher

class BiometricAuthenticationManager(private val context: Context) :
        BiometricPrompt.AuthenticationCallback() {

    private var biometricPrompt: BiometricPrompt? = null

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

    override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
        super.onAuthenticationSucceeded(result)

    }

    override fun onAuthenticationFailed() {
        super.onAuthenticationFailed()
    }

    fun init(cipher: Cipher, promptInfo: BiometricPrompt.PromptInfo) {
        if (context is FragmentActivity) {
            val executor = Executors.newSingleThreadExecutor()

            biometricPrompt = BiometricPrompt(context, executor, this)
            biometricPrompt?.authenticate(promptInfo, BiometricPrompt.CryptoObject(cipher))
        } else {
            throw Exception(
                    "Check for FragmentActivity context.")
        }
    }
}

For further reference about how it look like, please find following attachment.

I try to check same scenario for lock screen, where I guess it uses custom implementation using FingerPrintManager class and display message.

来源:https://stackoverflow.com/questions/57493822/how-to-identify-if-device-has-in-display-biometric-fingerprint-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!