用户关闭验证对话框时,不会触发Google Safety net addOnFailureListener

say*_*ana 6 sdk android recaptcha safetynet

注意我张贴的问题/问题谷歌样品GitHub库https://github.com/googlesamples/android-play-safetynet/issues/12。但是,我还没有得到任何回应。

使用的库版本: com.google.android.gms:play-services-safetynet:11.4.2

我正在使用安全网验证码API。一切均按预期含义工作,并且都检测到:-成功时(使用真实设备进行测试且未检测到危害时)-一个故障侦听器(使用Android模拟器进行测试并验证了步骤时)

但是,这里的步骤会产生无法检测到成功和失败的问题: -在Android模拟器中运行应用程序-使用验证码击打SafetyNet验证-由于android模拟器标记为可能有害,它将显示图像进行验证-单击“监听”图标听单词-在对话框区域外的屏幕上单击,验证对话框将关闭

预期:应该触发addOnFailureListener,因为当检测为机器人时用户未对验证步骤做出响应

实际:未检测到OnSuccessListener和addOnFailureListener

样例代码

SafetyNet.getClient(this).verifyWithRecaptcha(YOUR_API_SITE_KEY)
            .addOnSuccessListener((Executor) this,
            new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
                @Override
                public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
                    // Indicates communication with reCAPTCHA service was
                    // successful.
                    String userResponseToken = response.getTokenResult();
                    if (!userResponseToken.isEmpty()) {
                        // Validate the user response token using the
                        // reCAPTCHA siteverify API.
                    }
                }
        })
        .addOnFailureListener((Executor) this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (e instanceof ApiException) {
                        // An error occurred when communicating with the
                        // reCAPTCHA service. Refer to the status code to
                        // handle the error appropriately.
                        ApiException apiException = (ApiException) e;
                        int statusCode = apiException.getStatusCode();
                        Log.d(TAG, "Error: " + CommonStatusCodes
                                .getStatusCodeString(statusCode));
                    } else {
                        // A different, unknown type of error occurred.
                        Log.d(TAG, "Error: " + e.getMessage());
                    }
                }
        });
Run Code Online (Sandbox Code Playgroud)

问题:

  • 如果用户关闭验证对话框,然后SafetyNet不会通知侦听器,这是预期的设计吗?
  • SafetyNet是否有其他侦听器来处理上述问题?或其他通过SafetyNet SDK处理这种情况的解决方案?

谢谢

And*_*nok 0

Github 问题的解决方案是处理 onResume() 操作

当安全网验证码被取消时:在我的情况下,要求是当安全网验证码被忽略时结束按钮上的动画。因此用户可以再次单击它。

当安全网验证码失败时:他们建议关闭所有对话框 onResume()

在 Kotlin 中,答案应该是:

supportFragmentManager.fragments.takeIf { it.isNotEmpty() }?.map { (it as? DialogFragment)?.dismiss() }
Run Code Online (Sandbox Code Playgroud)

对于 java,您可以在这里找到答案: Android - How to Dismiss All Dialogs in onPause