gpt4 book ai didi

recaptcha - 在 Android Studio 3 中呈现 Google Recaptcha

转载 作者:行者123 更新时间:2023-12-04 08:54:04 27 4
gpt4 key购买 nike

我正在使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com