![]() |
Google reCAPTCHA is one of the services provided by Google which is used to verify whether the user is a bot or not. The Google reCAPTCHA is seen in many websites and applications to verify the users. In this article, we will take a look at the implementation of Google reCAPTCHA in Android. What we are going to build in this article?We will be building a simple application in which we will be displaying a Google reCAPTCHA verify user button, after clicking that button we will display the Google reCAPTCHA to our user and verify them. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. Working of Google reCAPTCHAWhile using reCAPTCHA it makes several calls from your application to the Safety Net server and from the Safety Net server to your application. So you can get to know about these calls in more detail in the below diagram. Steps in which we make API calls:
Step by Step ImplementationStep 1: Create a New Project To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language. Step 2: Adding the dependency for volley and Safety Net As we will be using the API provided by Google. So for using this API we will be using Volley for handling our HTTP requests and a safety net for connecting to Google reCAPTCHA.
After adding this dependency now sync your project and now we will move towards the creation of our API key which we will require for Google reCAPTCHA. Step 3: Generating API key for using Google reCAPTCHA For using Google reCAPTCHA we have to build two keys such as site key and site secret key which we have to use for authentication. For creating a new API key navigate to this Google developers site. And refer to the following diagram to generate the API keys. After adding this data accept reCAPTCHA terms and then click on Submit option. Step 4: Adding permissions for the Internet As we are calling the API for Google reCAPTCHA so we have to add permissions for the Internet in our AndroidManifest.xml. Navigate to the app > AndroidManifest.xml and add the below code to it. XML
Step 5: Working with the activity_main.xml file Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. XML
Step 6: Working with the MainActivity.java file Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail. Java
After adding this code make sure to add the keys which we have generated inside your app. After adding the keys run your app and see the output of the app. Output: |
Reffered: https://www.geeksforgeeks.org
Android |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |