Skip to main content

Post 4: Android: Android Login With Google Plus using Android Studio

Here we will show how to create a Google+ login Account for your Android application Using Android Studio:-

First you have to launch your Android Studio e1 and then enter into the Configure 
 and19

Here go for SDK Manager to check whether all the tools required for Google+ app is installed or not

and20 


Check you have any update for the Android SDK Tools, and Android SDK Platform tools if any there means just select them and Scroll down in search of Extras.
and21


Google+ is a part of Google play services API hence you have Download the Google Play services in SDK manager

g4

Now Create a new Project
-> Give the Application name for your project that you want and click on Next
->Choose the minimum SDK that you want for your application and click Next
->Choose the blank activity and hit on Next
->Choose the Activity Name that is suitable for your application but better to    choose the default activity

Download the Google Play services using Android SDK manger and add dependency to your build.gradle file


Getting the SHA-1 fingerprint which we have to give in Google Developers Console.

Java keytool is used to generate SHA-1 fingerprint. Open your command prompt and execute the following command to generate SHA-1 fingerprint and for passoword enter android if prompted.

For Linux or Mac OS:

For Windows:

Now you will find the generated SHA-1 fingerprint in your terminal
Android Login With Google Plus sha1 key

Creating your project in  Google Developers Console.


To authenticate and communicate with the Google+ APIs, you must create a Google Developers Console project where you have to enable the Google+ API and create an OAuth 2.0 Client ID.
3.1. Goto Google Developers Console. and create a new project
Android Login With Google Plus creating project
3.2. Once you are done with creating a project, Click on API’s under API’s and Auth section. Search for the Google+ API and select the one which i have shown in the below image.
Android Login With Google Plus choosing api
3.3. Enable the Google+ API by selecting the Enable API Button available.
Android Login With Google Plus enable api
3.4.After enabling goto the Credentials section under the API and Create a new Client ID.
Android Login With Google Plus create client ID
3.5. Select the Installed Application as the type and configure consent screen
Android Login With Google Plus consent screen
3.6. Now Fill out the package name of your project, paste the SHA1 finger print, enable the Deep Linking option to activate interactive posts and all the other parameters as shown in the image below .
Android Login With Google Plus package name Click on the create Client ID button and now you are done with creating your project in Google developer console.

Step 4: Declare permissions to your mainfest file.

Add a meta-data tag as a child of the application tag to declare the version of Google Play services you are using

 To access Google+ APIs:

 To retrieve the account name (email) as part of sign-in:

 To retrieve OAuth 2.0 tokens or invalidate tokens to disconnect a user. This disconnect option is required to comply with the Google+ Sign-In developer policies:

Finally, This is how your manifest file will after adding meta-data and all the permissions

eate a class MainActivity.java where we are going to do all our stuff for Google+ Login

  1. Your class must implement GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener and override all the methods.
  2. GoogleApiClient is used to communicate with the Google+ API and becomes functional after the asynchronous connection has been established with the service.
  3. In your OnCreate() method build a GoogleApiClient that uses the desired api.
  4. While building the GoogleApiClient in onCreate(),  If you need access to the user’s identity, social graph and the ability to write app activities, set the scope to PLUS_LOGIN (or) If you just need access to basic profile information, set the scope to profile.
  5. In your onStart() method start connecting the GoogleApiClient.
  6. On the Sucessfull connection OnConnected() method is called where we will be using thePlus.PeopleApi.getCurrentPerson method to request profile information the currently signed in user.
  7. When the GoogleApiClient object is unable to establish a connection onConnectionFailed() is called, where you are passed a ConnectionResult that can be used to resolve the error.
  8. Google Play services will trigger the onConnectionSuspended callback if our Activity loses its service connection. Here, We will be trying to reconnect the GoogleApiClient.
  9. Dont forget to disconnect the GoogleApiClient connection in onStop() method else lot of resources will be wasted.
MainActivity.java

 Step 6: Create activity_main.xml which will contain our login and logout layout .

This will be the code for signIn button:
 activity_main.xml


Thats it folks. You are done with Google+ Login. Follow me on GITHUB

Comments

Popular posts from this blog

Index: JSF

Java Server Faces Basics Post 1: JSF : Introduction to JSF  Post 2: JSF:  configuration files  Post 3: JSF: Installation Post 4: JSF: Your first JSF project   Standard JSF Tags Post 1: JSF: textbox example Post 2: JSF: password example Post 3: JSF: textarea example JSF 2 GraphicImage Example Post 4: JSF: GraphicImage Example Post 101 : JSF : The valueChangeListener Attribute Example

Index: iReport

iReport for Java ------------------------------------------------------------ Titles and Headers ------------------------------------------------------------ Post 1: iReport : Downloading, installing, and running JasperReports and iReport Post 2: iReport : Creating your first "Hello World" report   Post 3: iReport : Understanding iReport Elements Post 4: iReport : Creating and sizing the title for your report Post 5: iReport: Inserting a company logo in the title of your report  Post 6: iReport : Installation of PostgreSQL Post 7: iReport : Creating a report from relational data Post 8: iReport : Using dynamic titles that can change during report processing. Post 9: iReport : Adding a simple header to your report Post 10: iReport : Setting margins for your report and aligning the report header relative to report margins  ------------------------------------------------------------ Body and Footer ---------------------------------------------------------...