Saturday, March 16, 2019

Integrating Google Sign In in Android Application

Configuration of your project in Google API Console:

Following steps you have to follow before you start coding,

Create a new project in android studio. Now, in your app-level build.gradle file, add 


implementation 'com.google.android.gms:play-services-auth:16.0.1'
  
Now sign in to your google account from browser and open configure your project

At this point, you have already dependency in your gradle. So jump to the next step i.e.

Click on the Create a project




Now, if you have already created a project in google API Console and want to integrate google Sign In in that project then open drag down list and select existing project. Otherwise you can create a new project.




After clicking next, it will ask you the product name. Name your product whatever you want and then it will ask you where you are calling from. Here, we are creating an android application so we will opt Android.




So, next console will require details regarding your application package and SHA - 1 key.
You can copy your package name from your AndroidManifest.xml file.



Now, to generate SHA - 1 key for your project, do the following,

Go to Gradle that is present at right side in your android studio window, click on it. So it will show a tree structure. Select ApplicationName → ApplicationName (root) → Tasks → android → signinreport Now, run that signinreport by double clicking on it. Now you can see that SHA - 1 key is generated in Run windnow. Copy that key and paste in google API Console. 





Click on next and then download configuration file. Now paste that credentials.json file into your app directory. 


So, now prerequisites steps are completed Now you can jump to coding portionn. Before that include below dependency to your app-level build.gradle file, which is used to load image from given url.

implementation 'com.github.bumptech.glide:glide:3.6.0'  

Coding part:

activity_main.xml:



MainActivity.java:




activity_profile.xml:




ProfileAcitivity.java:




Now, add <uses-permission android:name="android.permission.INTERNET"/> in your AndroidManifest.xml file.

Run the application now. It will look like this,



Well, I hope you understand this and let me know if you have any doubts :D

No comments:

Post a Comment