7

I'm implementing Bio metric Prompt API for authorising user using Fingerprint. I found that Bio-metric Prompt API display different UI based on device sensor type.

enter image description here

Bio-metric API SDK call work independently to display respective UI based on sensor type.

enter image description here

Now the concern is:

  1. In case of rear(at side of device in some devices) sensored device, it display dialog which also use to display error if any.
  2. But in case of in/under display sensored device, it simply display a fingerprint impression and that does not display any error in case.

Now the question is:

  1. Is there any API feature using that in-display prompt can display error.
  2. In case not, how we can differentiate between both type of sensor device so can handle error explicitly.
4

3 回答 3

2

如果您仍然遇到此问题,最近发布的一篇博客文章阐明了 API 的行为方式为何。该帖子还向您展示了如何正确使用 API。

您应该只需要使用 AndroidX 中的生物识别库。

基本上你会得到三个回调:

  1. 当用户已使用设备识别的凭据进行身份验证时,将调用 onAuthenticationSucceeded()。

  2. 当发生不可恢复的错误时调用 onAuthenticationError()。

  3. 当用户被拒绝时调用 onAuthenticationFailed(),例如当传感器上放置未注册的指纹时,但与 onAuthenticationError() 不同,用户可以继续尝试进行身份验证。

您可以使用这些回调中的任何一个通过 Toast 等向您的用户发布消息。

于 2019-11-07T22:23:29.983 回答
1

在这种情况下,确实有一个 API 和回调供您使用。您正在寻找的包是 API 级别 28+的Biometrics包或 API 级别 23-27 的指纹包。

我所指的回调可以在这里找到API 28+ 和这里API 23-27。

下面是一些关于如何初始化回调的示例代码:

/**
 * Helper class for authentication callback
 */
@RequiresApi(api = Build.VERSION_CODES.M)
private class FingerprintHandler extends FingerprintManager.AuthenticationCallback {
    private FingerprintHandler(){}

    /**
     * Called when an unrecoverable error has been encountered and the operation is complete.
     * No further callbacks will be made on this object.
     * @param errMsgId An integer identifying the error message
     * @param errString A human-readable error string that can be shown in UI
     */
    @Override
    public void onAuthenticationError(int errMsgId, CharSequence errString) {
        //Authentication error. The 'errString' is meant to be displayed to the user
        //Handle logic here
    }

    /**
     * Called when a fingerprint is valid but not recognized.
     */
    @Override
    public void onAuthenticationFailed() {
        //Authentication failed (Fingerprints don't match ones on device)
        //Handle logic here
    }

    /**
     * Called when a recoverable error has been encountered during authentication. The help
     * string is provided to give the user guidance for what went wrong, such as
     * "Sensor dirty, please clean it."
     * @param helpMsgId An integer identifying the error message
     * @param helpString A human-readable string that can be shown in UI
     */
    @Override
    public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
        //Non-Fatal error (IE moved finger too quickly). The helpString can be displayed to the user to help them retry.
        //Handle logic here
    }

    /**
     * Called when a fingerprint is recognized.
     * @param result An object containing authentication-related data
     */
    @Override
    public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
        //Authentication Succeeded. They are good to go and it matches the stored one
        //Handle logic here
    }
}

如果上面的代码不足以让你动起来,这里是我的一个类中的一些示例用法。

关于使用警报或显示,如果我不想阻塞屏幕,我只需将回调信息与对话框或屏幕文本视图结合使用。

于 2019-09-25T17:25:50.163 回答
0

我认为您的问题与显示屏/后传感器无关。在我使用 Biometricx API 进行的测试分析中,我发现当生物识别身份验证失败时,显示屏内/后置传感器类型都在系统 UI 中显示错误。它还取决于您正在测试的设备,设备制造商可能已决定不支持生物识别 API。就我而言,当我在三星 S5 设备上进行测试时,即使设备有显示屏传感器,canAuthenticate() 也会返回 false。

于 2019-09-28T12:16:00.790 回答