![]() |
VOOZH | about |
Google reCAPTCHA is a service provided by Google which is used to verify the user whether is a user or a robot by providing them with a simple captcha to solve. In this article, we will be taking a look at How to integrate Google reCAPTCHA in the android application using Jetpack Compose.
To create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.
Below is the dependency for Volley which will be needed for using of reCAPTCHA. For adding this dependency navigate to the app > Gradle Scripts > build.gradle.kts(Module :app) and add the below dependency in the dependencies section.
dependencies {
...
implementation("com.android.volley:volley:1.2.1")
implementation ("com.google.android.gms:play-services-safetynet:18.1.0")
}
After adding the dependency simply sync your project to install it.
For using Google reCAPTCHA we have to build two keys as site key and the site secret key which we have to use for authentication. For creating a new API key navigate to this Google developer's 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.
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.
<uses-permission android:name="android.permission.INTERNET"/>Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
MainActivity.kt: