gpt4 book ai didi

android - 如何识别设备是否支持显示屏生物识别指纹?

转载 作者:行者123 更新时间:2023-12-04 11:05:01 25 4
gpt4 key购买 nike

我正在编写一个应用程序功能来使用 Biometric 对用户进行身份验证指纹认证API。它与 BiometricPrompt 的组合按预期工作API。

一般来说,它会显示自己的 UI 对话框,因此可以在 Android 设备上统一。(从 Fingerprint Manager API 改进)

在一种设备测试场景中,我遇到了 in-display (在屏幕上,例如 Oneplus 6T 设备)指纹支持而不是后部生物识别硬件选项。

当我在它上面运行应用程序时,调用 biometricPrompt.authenticate(..)它显示的不是对话框,而是显示指纹身份验证选项。没关系,由 BiometricPrompt 的内部 API 管理。

但它给开发人员管理带来了一些不一致。

  • 当它提供内置身份验证对话框时,所有回退错误都会显示在对话框本身中。
  • 但是在显示身份验证的情况下,我没有找到一种方法可以自行显示错误消息。而且我必须处理这种后备并以自定义方式显示。

  • 现在的问题是
  • 有没有办法通过显示身份验证 View 组件来管理/显示消息。
  • 如何识别设备是否支持设备内生物识别身份验证。

  • 编辑:我正在使用的代码引用:
    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.")
    }
    }
    }

    有关外观的进一步引用,请查找以下附件。

    enter image description here

    我尝试检查锁定屏幕的相同场景,我猜它使用了使用 FingerPrintManager 类和显示消息的自定义实现。

    enter image description here

    最佳答案

    前段时间面临同样的问题 - OnePlus 6T 没有生物识别用户界面,同时三星 A51 - 有自己的(自定义)指纹 API 用户界面和另一个用于 BiometricPrompt API 的用户界面。
    我试图观察 Activity 窗口焦点丢失(对于 OnePlus - Activity 不丢失焦点,同时 BiometricPrompt UI 导致焦点丢失),但三星设备出现问题。
    我找到的唯一解决方案,它现在有效:

  • 需要获取正确的设备名称(以一加为例,它不应该是 ONEPLUS A6003 ,而是 一加 6 )
  • 需要向 https://m.gsmarena.com/res.php3?sSearch=Device+Name 执行请求,你应该得到匹配的列表,通常需要第一个
  • 解析 HTML(来自预览步骤)以获取设备规范的链接(如 https://m.gsmarena.com/oneplus_6t-9350.php)
  • 现在您需要对该链接执行请求并再次解析 HTML 并获取“ 传感器 ”部分。你应该得到一个字符串,如“ 指纹(显示屏下,光学),加速度计,陀螺仪,接近度,指南针
  • 拆分此字符串以获取带有传感器的列表
  • 现在,当您需要检查设备上是否存在显示屏扫描仪时,只需检查同一传感器的“ 指纹”和“ 显示屏下的”。

  • Link与实现。可以作为一个例子

    关于android - 如何识别设备是否支持显示屏生物识别指纹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57493822/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com