DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Android Login with Google Plus Utility

Android Login with Google Plus Utility

Ketan Parmar user avatar by
Ketan Parmar
·
Dec. 08, 14 · Java Zone · Interview
Like (0)
Save
Tweet
3.07K Views

Join the DZone community and get the full member experience.

Join For Free

Pre-requisite

Official Document: https://developers.google.com/+/mobile/android/sign-in

Tutorial from AndroidHive : http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/

Note: Please read AndroidHive article for initial setup & other process

Usage

Step 1: Import "GooglePlusLoginUtils.java" class in your package


Step 2: Implement callback listener

public class LoginActivity extends Activity implements GooglePlusLoginUtils.GPlusLoginStatus

Step 3: Declare callback method

public void OnSuccessGPlusLogin(Bundle profile) {
 Log.i(TAG,profile.getString(GooglePlusLoginUtils.NAME));       
 Log.i(TAG,profile.getString(GooglePlusLoginUtils.EMAIL));
 Log.i(TAG,profile.getString(GooglePlusLoginUtils.PHOTO));
 Log.i(TAG,profile.getString(GooglePlusLoginUtils.PROFILE));
    }

Step 4: Declare object of GooglePlusLoginUtils.java

private GooglePlusLoginUtils gLogin;

Step 5: Initialize object in onCreate method

gLogin = new GooglePlusLoginUtils(this, R.id.activity_login_gplus); // Id of login button
        gLogin.setLoginStatus(this);

Step 6: Declare few supporting methods

@Override
 protected void onStart() {
         super.onStart();
         gLogin.connect();
 }
 @Override
 protected void onStop() {
         super.onStop();
         gLogin.disconnect();
 }
 @Override
 protected void onActivityResult(int requestCode, int responseCode,Intent intent) {
                gLogin.onActivityResult(requestCode, responseCode, intent);
 }

FAQ

Q: What is the problem of above approach ?

A: You activity has a lot of scattered code for Google Plus login, It will be more complex and unmanageable when you will have another social network login like Facebook and Twitter.


Q: How I will receive a response for login success?

A: You need to implement interface "GPlusloginStatus", on successful login you will receive callback "OnSuccessGPlusLogin"


Q: What will be received on login success ?

A: You will have Display name, Email , Photo and Profile url.


Q: Do I need to handle login failure / error ?

A: No, GooglePlusLoginUtils.java will handle login failure, error and display appropriate message on screen.  

Download Code

 


Google (verb) Plus (programming language) Android (robot)

Published at DZone with permission of Ketan Parmar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Time-Series Forecasting With TensorFlow and QuestDB
  • Top 5 Datadog Integrations To Improve the Efficiency of Tech Teams
  • Build a Serverless URL Shortener With Go
  • Verizon’s Data Breach Report: Cloud Security Insights

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo