Generally, those who develop an apps using Facebook and Google as the way to register beside the valid email.
The information that taken from Google and Facebook generally are name of account, email, profile picture and other public information.
Beside that, you also can post something to your Facebook home from your android application. I will post this topic soon. Interesting right?
For use your google account, you have to had Google email. After that fill the public information in your Google + account.
but, i think all of us have been had a Google plus account, right? So let start the implementation Login using Google plus account.
1. COMPILE THE LIBRARIES
Compile the following libraries in your build.gradle (Module : app):
In your build.gradle (Project : YourProjectName), paste the classpath below :
2. REGISTER YOUR PACKAGE NAME AND SHA-1 KEY
Actually this step for get the google-service.json. To get that file, you have to register your package project's name and SHA-1 key.
First find your SHA-1 key, take a look at the Figure 1 :
- Klik Gradle tab on the right side of your android studio IDE
- Klik the icon Refresh all the gradle projects
- Open :app/task/android/signingReport. Double click of signingReport.
- Your SHA-1 Key appears on the console.
Afte you find your SHA-1 Key, Open Developers.google console. Create new project or your can use your existing project.
To generating the google.service.json, just follow the figures below :
Guideline Figure 1 :
- Choose your project name (or create new one)
- Paste your package name
- Click the button Choose and configure services ~>
Guidelines fFigure 2 :
- Choose Google SignIn Mode
- Paste your SHA-1 Key
- Click Enable Google Sign In
Guideline Figure 3 :
Guideline Figure 4 :
- Download the google-service.json and place inside folder app in you directory project. Take a look at the figure 5
After that create your layout xml. Just simple layout for this tutorial. in this project i labelled as activity_google_login.xml. Here its code :
In your java class, there several steps that you have to know, there are :
Google Sign Options
Google Api Client
The flow of this method is, in case the users have logged in, when they open the apps again, user no need to login again because method getCache() will displaying the information. The point is, this method will work if the users don't logout the apps before.
After login, this method will set the display name and profile picture on you application. Glide will uses as the Image Loader from URL.
That's the main step that you have to know. Maybe the code above is still unclear for you, so the follows is the full code of java classes :