I’m developing an application on Android and I want to allow users to log in with their Google account. How can I achieve this?
You can't exactly log in to an Android application using a Google account. You use a Google account to login to a website or webservice such as GMail, Calendar, etc., or a third party website if using OpenID. Since your app is not an website, this won't work. You can do either one of:
AccountManager
) on their phone, and only let them use the app if they have one. If an account is registered, you can be reasonably sure that they know the password (or they stole someone's phone...)You might want to authenticate the user using one of the google account already configured in your device like some of the apps do, for that follow the below link -
"Authenticating to OAuth2 Services" - http://developer.android.com/training/id-auth/authenticate.html
Download Sample from Google - Android SDK Manager/Extras/Google Play Services
In simple steps it does
This is another link which is good in explaining the process - http://android-developers.blogspot.in/2013/01/verifying-back-end-calls-from-android.html
you can follow below steps for Login in your app
Below is response format of above "userinfo" call
{
"id": "ID",
"name": "NAME",
"given_name": "GiVEN NAME",
"family_name": "FAMILY_NAME",
"link": "https://plus.google.com/ID",
"picture": "https://PHOTO.jpg",
"gender": "GENDER",
"locale": "LOCALE"
}
If you want Email id along with that response you have to modify
SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";
to
SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
in that sample
**Dependency**
**Need Internet Permission**
**Working Code see Link on play Store**
https://play.google.com/store/search?q=com.codecube.airbucks
compile 'com.google.android.gms:play-services:8.3.0'
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="200dp"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:text="Logout"
android:id="@+id/btn"/>
</LinearLayout>
package com.keshav.geofencing;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
import utilities.CommonMethod;
import utilities.LoginPreferences;
public class LoginWithGmail extends AppCompatActivity
implements GoogleApiClient.OnConnectionFailedListener {
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private static final String TAG = "LoginActivity";
private static final int RC_SIGN_IN = 9001;
Button loginSub;
LinearLayout signInButton;
String gmailId;
String gmailName;
String gmailUserEmailId;
Uri gmailUserPhoto;
String savePassword;
LinearLayout btnlogin;
TextView btnsigning;
ProgressDialog prgDialog;
private CallbackManager callbackManager;
private BroadcastReceiver mRegistrationBroadcastReceiver;
private LinearLayout fbloginButton;
// private CallbackManager callbackManager;
private ProgressDialog mProgressDialog;
private GoogleApiClient mGoogleApiClient;
EditText edtEmail;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login1);
checkPermission();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(AppIndex.API).build();
// Google Sign up Button
signInButton = (LinearLayout) findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permissionCheck = ContextCompat.checkSelfPermission(LoginWithGmail.this, Manifest.permission.CAMERA);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
//showing dialog to select image
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
signInIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(signInIntent, RC_SIGN_IN);
Log.e("permission", "granted");
} else {
ActivityCompat.requestPermissions(LoginWithGmail.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1);
}
} else {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
signInIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
}
});
}
public void checkPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permissionCheck = ContextCompat.checkSelfPermission(LoginWithGmail.this,
Manifest.permission.CAMERA);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
//showing dialog to select image
if (CommonMethod.isNetworkAvailable(LoginWithGmail.this)) {
Log.e("keshav", "Permission if part marsh");
} else {
CommonMethod.showAlert("Internet Connectivity Failure", LoginWithGmail.this);
}
Log.e("keshav", "permission granted");
} else {
ActivityCompat.requestPermissions(LoginWithGmail.this,
new String[]{Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
}
}
}
@Override
protected void onResume() {
super.onResume();
// LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
// new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE));
}
@Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
super.onPause();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
// TODO ADD ME
@Override
public void onStart() {
super.onStart();
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.e(TAG, "Got cached sign-in");
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
showProgressDialog();
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
hideProgressDialog();
handleSignInResult(googleSignInResult);
}
});
}
}
// [START signOut]
private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// [START_EXCLUDE]
// updateUI(false);
// [END_EXCLUDE]
}
});
}
// [END signOut]
// [START revokeAccess]
private void revokeAccess() {
Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// [START_EXCLUDE]
// updateUI(false);
// [END_EXCLUDE]
}
});
}
// [END revokeAccess]
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// An unresolvable error has occurred and Google APIs (including Sign-In) will not
// be available.
Log.e(TAG, "onConnectionFailed:" + connectionResult);
}
private void showProgressDialog() {
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(true);
}
if (LoginWithGmail.this != null && mProgressDialog != null && !mProgressDialog.equals("null"))
mProgressDialog.show();
}
private void hideProgressDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()&& !mProgressDialog.equals("null")) {
mProgressDialog.hide();
}
}
// TODO ADD ME ENd
private void handleSignInResult(GoogleSignInResult result) {
Log.e("&&&s", "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
gmailId = acct.getId();
gmailName = acct.getDisplayName();
gmailUserEmailId = acct.getEmail();
gmailUserPhoto = acct.getPhotoUrl();
Log.e("gmailId", "is -->" + gmailId);
Log.e("gmailName", "is -->" + gmailName);
Log.e("gmailUserEmailId", "is -->" + gmailUserEmailId);
Log.e("gmailUserPhoto", "is -->" + gmailUserPhoto);
LoginPreferences.getActiveInstance(LoginWithGmail.this).setUserName(gmailName);
LoginPreferences.getActiveInstance(LoginWithGmail.this).setProfileImage(""+gmailUserPhoto);
Log.e("information", "using Gmail is > " + gmailId + " " + gmailName + "" + gmailUserEmailId + "" + gmailUserPhoto);
if (CommonMethod.isNetworkAvailable(LoginWithGmail.this)) {
Log.e("SignUp gmail", "Hit API..........................");
Intent i=new Intent(LoginWithGmail.this,DrawerActivity.class);
LoginPreferences.getActiveInstance(LoginWithGmail.this).setIsLoggedIn(true);
startActivity(i);
finish();
// TODO Here Registered User in own Database call Volley Retrofit2 Api ....
new SignUpSocialFacebookAsyncTask().execute();
} else {
CommonMethod.showAlert("Intenet Connectivity Failure", LoginWithGmail.this);
}
} else {
}
// TODO ADD ME KESHAV Google GMail Logout
Auth.GoogleSignInApi.signOut(mGoogleApiClient);
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Login Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.keshav.geofencing/http/host/path")
);
AppIndex.AppIndexApi.end(mGoogleApiClient, viewAction);
mGoogleApiClient.disconnect();
}
//Todo add new method for permission
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == RC_SIGN_IN) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
signInIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
}
}
**Dependency**
**Need Internet Permission**
**Working Code see Link on play Store**
https://play.google.com/store/search?q=com.codecube.airbucks
Take a look at http://developer.android.com/training/id-auth/index.html There you'll find a tutorial on how to use the Account Manager. (More specifically http://developer.android.com/reference/android/accounts/AccountManager.html)
Sure you might want to start with this:
Third-party websites and applications can now let visitors sign in using their Google user accounts. Federated Login, based on the OpenID standard, frees users from having to set up separate login accounts for different web sites--and frees web site developers from the task of implementing login authentication measures. OpenID achieves this goal by providing a framework in which users can establish an account with an OpenID provider, such as Google, and use that account to sign into any web site that accepts OpenIDs. This page describes how to integrate Google's Federated Login for a web site or application.
https://developers.google.com/accounts/docs/OpenID
Come back when you get stuck!
First insert the below line in your build.gradle dependencies
compile 'com.google.android.gms:play-services:7.5.0'
Now we need 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 [Open C:\Program Files\Java\jdk\bin then press Shift+Right Click] and execute the following command to generate SHA-1 fingerprint and for password enter android if prompted.
keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
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.
Now it’s time to declare permissions to your mainfest file. This is how your manifest file will look like after adding meta-data and all the permissions.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androstock.loginwithgoogle" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Now we are heading towards our MainActivity.java class where we are going to do all our stuff for Google+ Login.
package com.androstock.loginwithgoogle;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.plus.Plus;
import com.google.android.gms.plus.model.people.Person;
import java.io.InputStream;
// A project by Ferdousur Rahman Shajib
// www.androstock.com
public class MainActivity extends AppCompatActivity implements OnClickListener,
GoogleApiClient.ConnectionCallbacks, OnConnectionFailedListener {
// Profile pic image size in pixels
private static final int PROFILE_PIC_SIZE = 400;
/* Request code used to invoke sign in user interactions. */
private static final int RC_SIGN_IN = 0;
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
/* A flag indicating that a PendingIntent is in progress and prevents
* us from starting further intents.
*/
private boolean mIntentInProgress;
private boolean mShouldResolve;
private ConnectionResult connectionResult;
private SignInButton signInButton;
private Button signOutButton;
private TextView tvName, tvMail, tvNotSignedIn;
private ImageView imgProfilePic;
private LinearLayout viewContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic);
signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signOutButton = (Button) findViewById(R.id.sign_out_button);
tvName = (TextView) findViewById(R.id.tvName);
tvMail = (TextView) findViewById(R.id.tvMail);
tvNotSignedIn = (TextView) findViewById(R.id.notSignedIn_tv);
viewContainer = (LinearLayout) findViewById(R.id.text_view_container);
signInButton.setOnClickListener(this);
signOutButton.setOnClickListener(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
private void resolveSignInError() {
if (connectionResult.hasResolution()) {
try {
mIntentInProgress = true;
connectionResult.startResolutionForResult(this, RC_SIGN_IN);
} catch (SendIntentException e) {
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
/*
When the GoogleApiClient object is unable to establish a connection onConnectionFailed() is called
*/
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!result.hasResolution()) {
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,
0).show();
return;
}
if (!mIntentInProgress) {
connectionResult = result;
if (mShouldResolve) {
resolveSignInError();
}
}
}
/*
onConnectionFailed() was started with startIntentSenderForResult and the code RC_SIGN_IN,
we can capture the result inside Activity.onActivityResult.
*/
@Override
protected void onActivityResult(int requestCode, int responseCode,
Intent intent) {
if (requestCode == RC_SIGN_IN) {
if (responseCode != RESULT_OK) {
mShouldResolve = false;
}
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}
@Override
public void onConnected(Bundle arg0) {
mShouldResolve = false;
try {
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person person = Plus.PeopleApi
.getCurrentPerson(mGoogleApiClient);
String personName = person.getDisplayName();
String personPhotoUrl = person.getImage().getUrl();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
tvName.setText(personName);
tvMail.setText(email);
personPhotoUrl = personPhotoUrl.substring(0,
personPhotoUrl.length() - 2)
+ PROFILE_PIC_SIZE;
new LoadProfileImage(imgProfilePic).execute(personPhotoUrl);
Toast.makeText(getApplicationContext(),
"You are Logged In " + personName, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Couldnt Get the Person Info", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
signOutUI();
}
private void signOutUI() {
signInButton.setVisibility(View.GONE);
tvNotSignedIn.setVisibility(View.GONE);
signOutButton.setVisibility(View.VISIBLE);
viewContainer.setVisibility(View.VISIBLE);
}
private void signInUI() {
signInButton.setVisibility(View.VISIBLE);
tvNotSignedIn.setVisibility(View.VISIBLE);
signOutButton.setVisibility(View.GONE);
viewContainer.setVisibility(View.GONE);
}
/**
* Fetching user's information name, email, profile pic
*/
private void getProfileInformation() {
}
@Override
public void onConnectionSuspended(int arg0) {
mGoogleApiClient.connect();
signInUI();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
onSignInClicked();
break;
case R.id.sign_out_button:
onSignOutClicked();
break;
}
}
private void onSignInClicked() {
if (!mGoogleApiClient.isConnecting()) {
mShouldResolve = true;
resolveSignInError();
}
}
private void onSignOutClicked() {
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
signInUI();
}
}
/**
* Background Async task to load user profile picture from url
* */
private class LoadProfileImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public LoadProfileImage(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
Create activity_main.xml which will contain our login and logout layout .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:id="@+id/text_view_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:visibility="gone"
android:gravity="center">
<ImageView
android:id="@+id/imgProfilePic"
android:layout_width="80dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="20dp" />
<TextView
android:id="@+id/tvMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textSize="18dp" />
</LinearLayout>
<Button
android:id="@+id/sign_out_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@android:color/holo_red_light"
android:layout_marginLeft="19dp"
android:layout_marginRight="19dp"
android:text="LOGOUT"
android:textColor="#fff"
android:textStyle="bold"
android:visibility="gone" />
<TextView
android:id="@+id/notSignedIn_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:text="You are not Signed In"
android:textSize="20sp" />
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Thats it folks. You are done with Google+ Login. For more details you can visit here.