recaptcha - 在 Android Studio 3 中呈现 Google Recaptcha

标签 recaptcha android-studio-3.0

我正在使用 Android Studio 3

I am following this article to learn how to use Google Recaptcha in Android Studio.

使用此安装包:implementation 'com.google.android.gms:play-services-safetynet:12.0.1'
API key 也已注册。

我看到有 onClick 事件处理程序,但它在哪里提到渲染 recaptcha?

更新 1

当我编写链接中提到的按钮单击代码时...我收到一个复杂错误:不可转换类型无法将匿名 android.view.view.onclicklistener 转换为 java.util.concurrent.executor

评论中要求的代码

btn_Login.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View view) {
        SafetyNet.getClient(this).verifyWithRecaptcha("")
            .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();

                    } else {
                    }
                }
            });
    }
});

最佳答案

我使用了下面的代码,现在一切正常。

确保在事件 中实现 Executor

btn_Login.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View view) {
        SafetyNet.getClient(Activity.this).verifyWithRecaptcha("")
            .addOnSuccessListener((Activity) MyActivity.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((Activity) MyActivity.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();

                    } else {
                    }
                }
            });
    }
});

关于recaptcha - 在 Android Studio 3 中呈现 Google Recaptcha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49864635/

相关文章:

javascript - 如何在 SvelteKit 联系表单中获取 recaptcha token

javascript - 禁用按钮/防止编辑

android - 如何在 Android Studio 中高亮显示 Room Dao 的 SQL 语法

android - 获取 "Cannot find a version of ' com.android.support :support-annotations' that satisfies the version constraints"after Android Studio update

android - Gradle kotlin 不支持的方法 Dependencies.getAtoms()

zend-framework - Safari中音频reCaptcha的错误

ruby-on-rails - Rails 3/Recaptcha 安装 - 未定义的局部变量或方法 `recaptcha_tags'

internet-explorer - reCAPTCHA 在 IE 中触发 Java 警告

java - 以某种方式使用错误的 JDK(?)构建 Android 应用程序

android studio 3.0 设备资源管理器 - 运行为 : could not set capabilities: Operation not permitted