Android应用程序中的验证码

时间:2012-05-14 18:37:46

标签: android captcha

我必须在我的Android应用程序代码中实现Captcha,但不知道如何去实现它..

请有人帮帮我吗?

3 个答案:

答案 0 :(得分:3)

查看SimpleCaptchaJCaptcha

答案 1 :(得分:3)

无耻的自我推销,但我讨厌所有其他选择,特别是他们都是基于网络的。现在,我确信我需要很多工作等等,并且可能不像使用其他外部解决方案那样安全,但至少它易于使用并且有一些选择。

Git it here, and have fun changing and committing

答案 2 :(得分:0)

现在Google为此提供了SafetyNet reCAPTCHA库。
查找更多详细信息here

以下是实现reCaptcha的步骤:

  1. 添加SafetyNet API依赖项
dependencies {
    compile 'com.google.android.gms:play-services-safetynet:15.0.1'
}
  1. 使用API​​(来自Google文档的示例)

    public void onClick(View v) {
    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());
                    }
                }
        });
    

    }