Using Google reCAPTCHA in Android Application
In this tutorial, we will learn the working process of Google reCaptcha and integrate it in our Android application. Google's reCaptcha protects our application from malicious traffic. It is implemented using SafetyNet API.
Working of Google reCaptcha:
The Google reCAPTCHA is validated by calling the network calls between Android application, SafetyNet server and your server.
Generating the reCAPTCHA Site key and Secret key:
Before creating the API keys, read the API terms of services https://developers.google.com/terms/ carefully.
Android example of integrating Google reCAPTCHA
Let's create an example of integrating Google reCAPTCHA in our Android application.
Add the following SafetyNet and Volley dependencies in build.gradle file.
Add the internet permission in AndroidManifest.xml file
Add the following code in activity_main.xml file.
Add the following code in the MainActivity.java class file. In this class, we make the client side integration with SafetyNet server and get the response in JSON String.
Replace the value of SITE_KEY and SECRET_KEY with your actual Site Key and Secret Key. When clicking on the button, it calls the SafetyNet.getClient() method to get the Site Key, if returns success than call handleSiteVerify() for token verify.
The Volley library is used for the following purpose: