Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't cast this into Executor in google reCAPTCHA

Tags:

java

android

I have a problem with google recaptcha. I'm using theirs example from https://developer.android.com/training/safetynet/recaptcha#java but I get error when I try casting this into Executor.

Error which I get is: com.johny.Aktivity.Activity cannot be cast to java.util.concurrent.Executor.

I tried impementing Executor but then Android Studio forces me to include execute(Runnable) and recapcha always ends up there and not in the onSuccess() or onFailure().

like image 479
Honza Johny Pejsar Avatar asked Oct 29 '25 06:10

Honza Johny Pejsar


1 Answers

Actually, I'm not sure that why the code shown at android developer site is not working, but you can try below code in which I have just used different methods for success and failure listeners.

 SafetyNet.getClient(this).verifyWithRecaptcha("YOUR_API_SITE_KEY")
            .addOnSuccessListener(new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
                @Override
                public void onSuccess(SafetyNetApi.RecaptchaTokenResponse recaptchaTokenResponse) {
                    // Indicates communication with reCAPTCHA service was
                    // successful.
                    String userResponseToken = recaptchaTokenResponse.getTokenResult();
                    if (!userResponseToken.isEmpty()) {
                        // Validate the user response token using the
                        // reCAPTCHA siteverify API.
                        Log.e(TAG, "VALIDATION STEP NEEDED");
                    }
                }
            })
            .addOnFailureListener(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.e(TAG, "Error: " + CommonStatusCodes
                                .getStatusCodeString(statusCode));
                    } else {
                        // A different, unknown type of error occurred.
                        Log.e(TAG, "Error: " + e.getMessage());
                    }
                }
            });
like image 176
Rikin Prajapati Avatar answered Oct 31 '25 19:10

Rikin Prajapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!