【发布时间】:2018-04-16 19:12:20
【问题描述】:
我正在使用 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 密钥也被注册。
我看到有 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 {
}
}
});
}
});
【问题讨论】:
-
你能把你的代码贴在这里吗?
-
这与链接中提到的代码相同。我按照您的回答中提到的所有内容进行操作,但面临上述编译错误。 不可转换的类型不能将匿名的 android.view.view.onclicklistener 转换为 java.util.concurrent.executor
标签: recaptcha android-studio-3.0