如何处理三星指纹识别遮挡层阻止应用交互的问题
三星设备指纹验证弹窗阻断交互问题解决方案
问题根因
三星One UI系统默认会对生物验证失败的场景弹出系统级提示窗,该窗口优先级高于应用内自定义弹窗,会抢占应用交互焦点,导致用户无法操作应用。
方案1:规避三星系统级弹窗
- 调用AndroidX BiometricPrompt API时,主动覆写
onAuthenticationError回调逻辑,拦截指纹验证失败的错误码,完全由应用自己处理错误提示,不要走系统默认的错误展示逻辑,即可阻止三星弹出系统窗口:
val biometricPrompt = BiometricPrompt(this, mainExecutor, object : BiometricPrompt.AuthenticationCallback() { override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { // 拦截指纹锁定、验证失败相关错误码,自行处理提示 when (errorCode) { BiometricPrompt.ERROR_LOCKOUT, BiometricPrompt.ERROR_LOCKOUT_PERMANENT, BiometricPrompt.ERROR_USER_CANCELED, BiometricPrompt.ERROR_NO_MATCH -> { // 自行展示自定义弹窗,不要调用super.onAuthenticationError showCustomAttemptAlert(remainingAttempts) } else -> super.onAuthenticationError(errorCode, errString) } } override fun onAuthenticationFailed() { // 验证失败直接走自定义提示,不走系统逻辑 showCustomAttemptAlert(remainingAttempts) } })
注意:如果使用已废弃的FingerprintManager兼容旧版本系统,同样不要调用任何系统自带的提示展示方法,所有错误逻辑完全自行处理即可
方案2:自定义弹窗多实例管理(弹出新窗自动关闭旧窗)
全局维护唯一的指纹错误提示弹窗实例,每次弹出新窗前先销毁已存在的弹窗,避免多弹窗重叠:
// 全局保存当前活跃的弹窗实例 private var currentFingerprintAlert: AlertDialog? = null private fun showCustomAttemptAlert(attemptsLeft: Int) { // 先关闭已展示的旧弹窗 currentFingerprintAlert?.takeIf { it.isShowing }?.dismiss() // 创建并展示新弹窗 currentFingerprintAlert = AlertDialog.Builder(this) .setMessage("Incorrect Touch ID, attempts left:$attemptsLeft") .setPositiveButton("确认", null) .show() } // 页面销毁时清空实例避免内存泄漏 override fun onDestroy() { currentFingerprintAlert?.dismiss() currentFingerprintAlert = null super.onDestroy() }
内容的提问来源于stack exchange,提问作者Andrey Arshavin
相关产品推荐
相关产品推荐

