Integrate Google Sign In Into Android

Integrate Google Sign Into Android:-

We will integrate Google sign in into Android app. Google let users sign in through their Gmail account in their Android app.Google signing we get all the user details such as profile details, image, contacts very easily and quickly.

Integrating Google sign in into your Android app lets users sign quickly without the need for the complex registration process.

Configure Google Sign in:-

In order to integrate Google Sign In we need to first go ahead and set up the project on the Google developer console. We need to add google-services.json file to your project’s app folder. Please visit on the link here.

This will take you to link where you will be prompted to enter app name and package name as shown below.

Enter the project name if not create a project.

Then enter the project package name.

Click on choose and now we get the next screen where we need to add our SHA1 key.

Generate SHA1 Key :-

Now we need Java keytool to generate SHA1 fingerprint so, in order to use Java keytool, you must have Java installed on your machine.Then you go to your command prompt and type the following command below to generate the SHA1 fingerprint.

you can skip this if you want to do signin just for demo purpose but, if you want to do a backend validation we need google signin to generate a token and send to our REST server which will do the validations and authentication. This step is needed if you want to pass the currently signed-in user to a backend server, send the ID token to your backend server and validate the token on the server.Visit Google developer console . Select the appropriate project and click on Credentials.

You see list of OAuth 2.0 client IDs, select Web client (Auto-created for Google Sign-in) and copy the client id and store it in a string resource as

1

<stringname="server_clientid">Your Copied Web Client Key</string>

We are using this key when we create an object of GoogleSignInOptions as below in MainActivity.java

Now Open your MainActivity.java and add below set of code step by step.