Last active
September 5, 2018 04:52
-
-
Save prasannajeet/5864528456f581cdaf71896eba790da1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SuccessListener implements OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse> { | |
@Override | |
public void onSuccess(final SafetyNetApi.RecaptchaTokenResponse recaptchaTokenResponse) { | |
String userResponseToken = recaptchaTokenResponse.getTokenResult(); | |
if (!userResponseToken.isEmpty()) { | |
RecaptchaResponseViewModel mViewModel = ViewModelProviders.of(MainActivity.this).get(RecaptchaResponseViewModel.class); | |
mViewModel.getmRecaptchaObservable("https://www.google.com", userResponseToken, **SECRET KEY GOES HERE**).observe(MainActivity.this, new Observer<RecaptchaVerifyResponse>() { | |
@Override | |
public void onChanged(@Nullable RecaptchaVerifyResponse recaptchaVerifyResponse) { | |
if (recaptchaVerifyResponse != null && recaptchaVerifyResponse.isSuccess()) { | |
// User is a human. Congratulations! | |
} else { | |
// Response validation failed. Handle scenario | |
} | |
} | |
}); | |
} else { | |
// Device side validation resulted in no token. Failure | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment