Google+ sign-in lets users sign in to your Android app with their existing Google account and get their profile information like name, email, profile pic and other details. By integrating google plus login in your apps, you can get all the user details in one shot. Not only login, you can do other things like posting to their g+ account, getting list of circles, friends list and lot more. The major advantage of integrating G+ login is, you can drive more users to your app by providing quicker & easiest way of registration process.

android login with google plus account

So let’s start by doing required setup.

1. Installing / updating Google Play Services

Google plus is a part of Google Play Services API. So first we need to download the google play services in Android SDK manager. If you have already installed play services, it it very important to update it to latest version. Open the SDK manager and install or update the play services under Extras section.

android sdk manager installing play services

2. Generating Google-Services.json

Now all the android projects which uses google apis, requires google-services.json file to be placed in project’s app folder. Follow the below steps to get your google-services.json file.

2.1 Java keytool can be used to generate SHA-1 fingerprint. Open your terminal and execute the following command to generate SHA-1 fingerprint. If it ask for password, type android and press enter.

On windows

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

On Linux or Mac OS

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

In the output you can notice SHA1 fingerprint.

android generating sha1 fingerprint

2.2 Goto android quick start guide and click on Get A Configuration File button. This will redirect you to a page where you can choose the project and package name.

2.3 Create / choose an app and give your current app package name. I gave my package name as info.androidhive.gpluslogin.

2.4 Paste the SHA-1 fingerprint and click on Enable Google Sign-In. Finally click on Generate Configuration File to download your google-services.json

android-google-plus-google-services-json

3. Creating New Project

3.1. Create a new project in Android Studio from File ⇒ New Project. When it prompts you to select the default activity, select Blank Activity and proceed.

While filling the project details, use the same package name which you gave in google console. In my case I am using same info.androidhive.gpluslogin

3.2. Open project level build.gradle and add ‘com.google.gms:google-services:3.0.0’ class path to dependencies.

dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }

3.3. Open app level build.gradle and add ‘compile com.google.android.gms:play-services-auth:9.2.1’ to dependencies. At the bottom of the file, add apply plugin: ‘com.google.gms.google-services’

You can notice that, Glide dependency also added here to load the google profile picture in image view. This is completely optional.

dependencies {
    // ..
    compile 'com.google.android.gms:play-services-auth:9.2.1'

    // glide is added to load the g+ profile image. Ignore if you want
    compile 'com.github.bumptech.glide:glide:3.7.0'
}

apply plugin: 'com.google.gms.google-services'

3.4 Open strings.xml file located under res ⇒ values and add following strings.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">G+ Login</string>
    <string name="action_settings">Settings</string>
    
    <!-- Button text -->
    <string name="btn_logout_from_google">Logout from Google</string>
    <string name="btn_revoke_access">Revoke Access</string>
</resources>

3.5. Now I am designing a simple layout to display user’s profile picture, name, email and other buttons. Paste the below code in layout file of your main activity. In my case my layout file name is activity_main.xml

<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"
    android:padding="16dp"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/llProfile"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:orientation="horizontal"
        android:weightSum="3"
        android:visibility="gone">

        <ImageView
            android:id="@+id/imgProfilePic"
            android:layout_width="80dp"
            android:layout_height="wrap_content" 
            android:layout_weight="1"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:orientation="vertical"
            android:layout_weight="2" >

            <TextView
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/txtEmail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:textSize="18dp" />
        </LinearLayout>
    </LinearLayout>

    <com.google.android.gms.common.SignInButton
        android:id="@+id/btn_sign_in"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp"/>

    <Button
        android:id="@+id/btn_sign_out"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_logout_from_google"
        android:visibility="gone" 
        android:layout_marginBottom="10dp"/>

    <Button
        android:id="@+id/btn_revoke_access"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_revoke_access"
        android:visibility="gone" />

</LinearLayout>

3.6 . Now open MainActivity.java and do the below modifications. The code is self explanatory and very easy understand.

> implement the activity from GoogleApiClient.OnConnectionFailedListener

> Create the GoogleApiClient instance in onCrate() method.

> signIn() performs google plus sign in, signOut() logs out user from google account and revokeAccess() completely revokes the access from google plus.

> onActivityResult() is called whenever user returns from Google Login UI.

> In onStart() method, checked for cached google sign in session and appropriate UI is displayed.

> handleSignInResult() handles the google plus profile information upon successful login.

> updateUI() toggles the UI by showing / hiding the appropriate buttons and text views.

package info.androidhive.gpluslogin;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
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.SignInButton;
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;

public class MainActivity extends AppCompatActivity implements
        View.OnClickListener,
        GoogleApiClient.OnConnectionFailedListener {

    private static final String TAG = MainActivity.class.getSimpleName();
    private static final int RC_SIGN_IN = 007;

    private GoogleApiClient mGoogleApiClient;
    private ProgressDialog mProgressDialog;

    private SignInButton btnSignIn;
    private Button btnSignOut, btnRevokeAccess;
    private LinearLayout llProfileLayout;
    private ImageView imgProfilePic;
    private TextView txtName, txtEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in);
        btnSignOut = (Button) findViewById(R.id.btn_sign_out);
        btnRevokeAccess = (Button) findViewById(R.id.btn_revoke_access);
        llProfileLayout = (LinearLayout) findViewById(R.id.llProfile);
        imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic);
        txtName = (TextView) findViewById(R.id.txtName);
        txtEmail = (TextView) findViewById(R.id.txtEmail);

        btnSignIn.setOnClickListener(this);
        btnSignOut.setOnClickListener(this);
        btnRevokeAccess.setOnClickListener(this);

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        // Customizing G+ button
        btnSignIn.setSize(SignInButton.SIZE_STANDARD);
        btnSignIn.setScopes(gso.getScopeArray());
    }


    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }


    private void signOut() {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        updateUI(false);
                    }
                });
    }

    private void revokeAccess() {
        Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        updateUI(false);
                    }
                });
    }

    private void handleSignInResult(GoogleSignInResult result) {
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();

            Log.e(TAG, "display name: " + acct.getDisplayName());

            String personName = acct.getDisplayName();
            String personPhotoUrl = acct.getPhotoUrl().toString();
            String email = acct.getEmail();

            Log.e(TAG, "Name: " + personName + ", email: " + email
                    + ", Image: " + personPhotoUrl);

            txtName.setText(personName);
            txtEmail.setText(email);
            Glide.with(getApplicationContext()).load(personPhotoUrl)
                    .thumbnail(0.5f)
                    .crossFade()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(imgProfilePic);

            updateUI(true);
        } else {
            // Signed out, show unauthenticated UI.
            updateUI(false);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();

        switch (id) {
            case R.id.btn_sign_in:
                signIn();
                break;

            case R.id.btn_sign_out:
                signOut();
                break;

            case R.id.btn_revoke_access:
                revokeAccess();
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        }
    }

    @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.d(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);
                }
            });
        }
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        // An unresolvable error has occurred and Google APIs (including Sign-In) will not
        // be available.
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
    }

    private void showProgressDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage(getString(R.string.loading));
            mProgressDialog.setIndeterminate(true);
        }

        mProgressDialog.show();
    }

    private void hideProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.hide();
        }
    }

    private void updateUI(boolean isSignedIn) {
        if (isSignedIn) {
            btnSignIn.setVisibility(View.GONE);
            btnSignOut.setVisibility(View.VISIBLE);
            btnRevokeAccess.setVisibility(View.VISIBLE);
            llProfileLayout.setVisibility(View.VISIBLE);
        } else {
            btnSignIn.setVisibility(View.VISIBLE);
            btnSignOut.setVisibility(View.GONE);
            btnRevokeAccess.setVisibility(View.GONE);
            llProfileLayout.setVisibility(View.GONE);
        }
    }
}

5. Testing the app

On Real Device:
You can directly test this app on a real devices which is having Google account connected.

On Emulator:
You can also test the application on an emulator which runs Android 4.2.2 or greater. Follow below link to know how to configure an emulator by installing Google Play Services.
Configuring emulator with Google Play Services

If user clicks on sign in button, the following popup will be shown asking user to sign-in using google plus account.

android-google-plus-sign-in-choosing-the-account
android-sign-in-with-google-plus-account
Change Log

Updated On 2nd Sep 2016 (Content Update, Bug fixes)
Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.
  • Nicolas

    Hi,

    Very good tutorial, as always !
    Thank’s from France !

    • You are welcome 🙂

      • Cristiana

        Hi Ravi do you have sample apk for this toturial ? i have error , i am using android studio.

  • Jeffy Lazar

    This blog is awesome and
    This guy “RAVI TAMADA “is a super helpful genius

    Thanks alot man for your hardwork shown in this great tutorials
    really helps alot 🙂 🙂

  • Vaibhav

    not getting the meta data value in manifest @integer/google_play_services_version

    • Make sure that you updated Play Services to latest version and import the library again.

      • Vaibhav

        I am using the latest version of play services i.e. 15 but not getting option @integer to add.. i am using app version 10…is this an issue..?

        • No app version won’t be an issue. Please open SDK manager and re check again. Why because I got the same problem.

          • Vaibhav

            @ravi8x:disqus thnks ..i have deleted my google play lib and download and install it again.. i got the option.. thanks for your help..

          • gie

            adadsad

        • Leonardo Lopes

          I Know how to solve this issue. At eclipse IDE you need dont paste the lib at lib folder. At Package explorer make a right click on mouse and select import projects, already existent android project and select folder that contains your google play services.

          After that, a new project called same name of the library will appear.

          Next step, is make this project as a library.

          Click right button on the new project and select properties. check options is a library.

          Now is all ready to use this library, in your project go to the properties, and in list of library’s right down the check “is a library” click at “add” and select google play project.

          I Hope help you.

          More information can be founded at:

          http://developer.android.com/google/play-services/setup.html

          Best regards

          Leo

  • Ranjit Paul

    Getting error on Plus field

  • Pavlos

    Keep up the great work mate!! Congrats!

  • Sushil

    I want to integrate it into my app .. but every time i try to start the Activity containing G+ Login the app crashes .. The other activities work fine

  • Dave

    Hi, I have problem, I pushed sign in button, then I pick my account from the list, and then I received something like: “Internal error”. Can you help me?

  • mina mohsen

    iam getting this error in the xml file:-
    The following classes could not be instantiated:
    – com.google.android.gms.common.SignInButton

    and the button is not seen

    • Andrew

      The Google Plus library hasn’t been added as a library then.

      • mina mohsen

        this is only in the design page only , the java classes work normly ??

        • Andrew

          Try cleaning your project. I was able to implement the button in a similar solution inside android studio (refresh gradle if you are using that). Also check for any kind of typo or parameter that doesn’t go with that view. For some reason I type amdroid: instead of android: a lot.

  • Craig

    Thanks mate,
    Small note, if you’ve a project created with the old console, it won’t have a project id, this will cause you to get an ‘internal error has occured’ toast when trying to sign in. You need to create a new API project and specify a project id, and create the auth id there (if you’ve already added one to your old project, delete it first).

    • Anil Chahal

      Thank you so much dear .. i was facing this problem, and i did what you just written above.. Good observation .. Thanks again. 🙂

    • wladimir

      Hi, Can you tell more precisely where to add project Id, and how to use it in code?

  • Connie Leung

    Is it possible design camera app that takes picture and then upload to G+ account? Please advise. Thanks.

  • Anil Chahal

    Great work Ravi. Keep it up .. This blog is simply rocking man. Congrts.

  • Kumar

    Good work Ravi..Nice blog for android community

  • Once again a very simple and easy to understand tut.

    Thanks very much! Your a great help

    Matt

  • Great tutorial,

    how ever do i have to run this on an a real device because i get update google play services when i run?

    • worked after updating google play services, awesome tutorial again

  • Phuc Nguyen

    Great article! Thanks so much

  • Hasnain Ali

    when I run on real device got “An internal error occur”

  • Rami

    I got “An internal error occur”

    • Sumit Ingewar

      Please check that you have registered right package name on API Console

  • Vihang

    I got “An internal error occur” what can i do solve this error. .

  • Riyas V

    Great tutorial man, Thank you very much.

  • Tugsbayar

    Hi. Is it possible to log in by custom email of google. For example: i have mail@domain.com. When i log in program let me download things. When i log in by other email such as @gmail.com i can not download things.

  • Guest

    03-02 09:56:23.745: E/AndroidRuntime(1536): FATAL EXCEPTION: main

    03-02 09:56:23.745: E/AndroidRuntime(1536): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.gpluslogin/info.androidhive.gpluslogin.MainActivity}: android.view.InflateException: Binary XML file line #47: Error inflating class com.google.android.gms.common.SignInButton

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.ActivityThread.access$600(ActivityThread.java:141)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.os.Handler.dispatchMessage(Handler.java:99)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.os.Looper.loop(Looper.java:137)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.ActivityThread.main(ActivityThread.java:5103)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at java.lang.reflect.Method.invokeNative(Native Method)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at java.lang.reflect.Method.invoke(Method.java:525)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at dalvik.system.NativeStart.main(Native Method)

    03-02 09:56:23.745: E/AndroidRuntime(1536): Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class com.google.android.gms.common.SignInButton

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.createView(LayoutInflater.java:620)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.Activity.setContentView(Activity.java:1895)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at info.androidhive.gpluslogin.MainActivity.onCreate(MainActivity.java:65)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.Activity.performCreate(Activity.java:5133)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)

    03-02 09:56:23.745: E/AndroidRuntime(1536): … 11 more

    03-02 09:56:23.745: E/AndroidRuntime(1536): Caused by: java.lang.reflect.InvocationTargetException

    03-02 09:56:23.745: E/AndroidRuntime(1536): at java.lang.reflect.Constructor.constructNative(Native Method)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at android.view.LayoutInflater.createView(LayoutInflater.java:594)

    03-02 09:56:23.745: E/AndroidRuntime(1536): … 22 more

    03-02 09:56:23.745: E/AndroidRuntime(1536): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$drawable

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.internal.ei.b(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.internal.ei.a(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.common.SignInButton.c(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.common.SignInButton.p(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.common.SignInButton.setStyle(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.common.SignInButton.(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): at com.google.android.gms.common.SignInButton.(Unknown Source)

    03-02 09:56:23.745: E/AndroidRuntime(1536): … 25 more

    • ;)

      Check the Id od the buttons you have used..

  • Guest

    this part of source doesn’t work for me

  • ravi kiran

    This code works like charm but how to make sign out from different activity

  • Guest

    shi*!!! I did run this on api 17 bu not google.inc, this was my trouble, thanks for tutorial!

  • Mahesh kavathiya

    Hi Ravi thanks for your all tutorial i am always using your tutorial.but in this tutorial i have minor problem.how to change google+ icon. i mean can we set by default icon to our image or any icon instead of google+ icon.

  • Wa

    Thank you for the tutorial but I got an internal error.

  • Pinal Jakhar

    Hi..

    I am following this tutorial but getting the ‘internal error’ issue again and again.
    However, I had created android project using a different gmail account and my device is configured with different gmail account. Can this be the cause for this ‘internal error’ ?
    Do we need to add our android app’s Client Id somewhere?

    • Mahesh kavathiya

      please create your own application project in google developer console after run this project may be working perfact..but make sure package name will be same your project and google developer consol.

      • Pinal Jakhar

        I have created my application in the developer console, but with a different gmail account. But I think this tutorial is using the USE_CREDENTIALS permission to request the authtokens of the gmail account configured in the device. I want to use the gmail account for which I have developed the application. I want to know is there any way by which I can use the Client Id generated for my application

        • Mahesh kavathiya

          Yes pinal jakhar this tutorial only get device configured gmail information.you can not use any other gmail account for this tutorial..

          • Pinal Jakhar

            I tried to find out how to do that with some other gmail account, but all in vain. I wonder if this Google Play Services sdk provides this option or not? There must be some provision for using other gmail account

    • thanks…

  • adu

    I have an error: com.google.android.gms.plus.Plus cannot be resolved.

    • Abdul Wasi

      have you solve this problem? i have same issue

  • Mamro Kirill

    G + Returns age and a floor?

  • ram

    Thank you very much…

  • Shree

    Hi ravi,
    I had done exact setup as mentioned in your tutorial and but my device where i had deployed this app shows “internal error”, again and again.Can you tell us how to change package name or unique id created in google api console to run this project.
    If api and Package names are problem then what is way around to circumvent. I am using client side, desktop so it means that once keys are generated using same desktop will not be able to run this project.

    Thanks,

  • Sushilkumar Yadav

    hie Ravi .. i need your help .. i have tried integrating G+ login in my app .. but it is throwing error ..”An Internal Error Occurred” .. Plz help it is my final year project ..

    • I solved the same problem adding in Google Developers Console the permissions also for Google+ Domains API and editing the Consent screen for my project. I hope that this can help you!

      • ramadon

        can u show me detail ? I got this problem too

      • Akhil chandran

        how to edit the Consent screen. please help

  • Gregory Galera

    Using google+ api on android, is it possible to allow a user to log in only on the first time they ever use the app, and from that point the app is always logged in auomatically, even after a device restart, and if so, can someone point me in the right direction?

  • Matthias

    I”m also getting the internal error when trying to sign in.

    • Tonyoh87

      same for me

      • Matthias

        Solution: Add Google+ Domains API in the Google Developpers Console to your project and edit/fill in your Consent Screen. Note that this whole setup works with debug keys, which means you’re the only one who could use them. When you release the app you must change them to release keys. That way it works for me.

        An other possibility is to integrate the SocialAuth-Android and SocialAuth SDKs in your project, that way you can access multiple social networks through a uniform interface with public/private key pairs (so not via the Google+ or Facebook app for instance). I integrated this in my current application and it’s a fantastic API.

        • Tonyoh87

          how do you do this with Eclipse ? I don’t use the google developpers console…

          • Matthias

            It has nothing to do with your IDE. The Google Developpers Console is a website. Depending on your settings/permissions, an app can or cannot fail. You don’t have to change your code or environment for setting up the permissions. If you use your app you contact Google somehow and they check your permissions.

        • Amintas

          Awesome Matthias, I did the first option and it worked for me!

          “Add Google+ Domains API in the Google Developpers Console to your project and edit/fill in your Consent Screen.”

          Thanks!

  • shashi shiva

    I’am getting internal error in a real devise when signing in. When i run on emulater, it displays a message “This app won’t run without Google Play services, which are missing from your phone”. Please do replay.

  • the above app works for me on my smart phone but the only thing it misses for me is the formatting !!
    my fetched profile picture and never comes besides my name and the email id as shown above in the screenshot !! (last one containing the fetched profile )
    can any one please seem to help ?

  • Twinkle

    Thank you so much for this tutorial . but could you please update tutorials with using fragments and android studio

  • olbers

    this is nice tutorial., i like that’s

  • Nikhil

    how do we revoke access from another activity?

  • Guest123

    HIii Ravi..,i have tried integrating G+ login in my app .. but it is showing an error ..”An Internal Error Occurred” .. Please help me to resolve it ..

    • Bracebie

      Check ur client ID in Google developer console again. Maybe u have fill the wrong package name or wrong HASH key. And don’t forget to fill ur email in “Crescent screen” in the APIs and auth tab.

  • Guest123

    i have one more question,when we login through facebookSDK it takes the app_id generated by facebook, but in this don’t we need app_id genrated by google,if yes then from where we are passing that..??

    • Bracebie

      It generated by client ID in the Google developer console website. When u create the client ID you need to put the correct information about ur app’s package name and HASH key.

  • Gerard Caceres

    hello ..

    good contribution ..

    but I always get “internal error” may be happening.

    code

    mGoogleApiClient.isConnecting ()

    returns false

    • Mohamed Tlili

      I have same problem I resolve it by creating a new project in the console of google developper be carefull the name of the project is same name of your project and activate Goole API

      • Gerard Caceres

        yes, me and set this right ..

        but it keeps coming out the same error message ..

        • Bracebie

          You need to put ur email in the “Cresent screen” below APIs and auth tab in the Google Developer Console.

  • Sachin Fulzele

    I have fix “internal error” problem and even after creating 10 different client IDs with different SHA and package name, it doesn’t work…
    until I found out that you have to fill the “Consent screen” in your account.

    • Pankaj Pardhi

      Thank you Sachin. I think also the Blog must also needs to be updated with the correction that you have provided. Mr Ravi Tamada, this seems to be the common problem for most of the people if you read the comments. Please make a note about it.

      • Thanks @sachinfulzele:disqus & @pankajpardhi:disqus. I’ll update this post, even I still have to find out exact reasons for Internal Error.

        • Goku

          Did you find anything? i just started developing for android. Ass i came accross the same problem, i cant find any sollusion.

        • Wes

          Hey Ravi. Awesome tutorial! You really know how to make things pretty succinct! I noticed a lot of people complaining about the whole internal server error. I read somewhere that the keystore SHA1 fingerprint on the development device sometimes expires. To get a fresh one, just delete the debug.keystore file from users.android folder and then rebuild any app again in Eclipse. Then when you go to Window–>preferences–>android–>build, you’ll see a new debug SHA1 fingerprint. Copy that fingerprint and paste it in your Android Client ID generator for your app on developer console. The rest of the steps remain the same again. Maybe it will clear the error. Just a thought.

  • Diane Bevington

    Hi everybody, is anyone else running into a problem where only the first user can sign in indefinitely? I can’t figure out how to switch emails!!

    I am running into a fault where now that I have logged in with my gmail account, I cannot choose which email to log in with anymore. The first screen popped up where I accepted “dibe****@colorado.edu”. Now, even after pressing the “Revoke Access” button, when I hit sign back in, it still takes me to my access page, already with my picture and information.

    My question is: how do I allow others to log in to this app????

    • Kevin C

      I’m having the exact same problem right now..

  • Kevin C

    Hi,

    First of all, thanks for the tutorial. Everything works as I want it except for one last thing:

    If I restart the app, or after an user has Revoked Access, and then I click on the Google+ log-in button, I immediately go to the Permissions screen with the last logged-in user, instead of the Google+ log-in screen?

    I thought the Revoke Access would make me able to log-in again with a different (or the same) Google+ account with Google+ account & password, but instead I’m skipping this step for some reason and go to the Permission Screen of the last logged-in user..

    How do I fix this having the same code as you’ve shown above?

    Thanks in advance for the response,

    Greetz,
    Kevin C

    • Kevin C

      Ok, I did figure out how to switch accounts, but it’s done through the Device Settings itself. Settings -> Accounts -> Google -> Add account (and I’ve deleted the other account).

      Still, is there a way to Log-in with Google+ email & password inside the app, instead of changing the Settings first and then go to the app?

      Greetz,
      Kevin C

      • Kevin C

        Does someone know how to make a Login Screen, so you log-in with a Google Account by typing e-mail & password, instead of using the Android Device’s Account (and right now it’s also only using the last logged in Account..)

  • amr khamis

    hey can i use this login authentication for using youtube features for example posting likes for a certain video or comments ?? can u make a tutorial how to login to youtube account and use its api for making likes and comments and subscribing ??

  • সাদ মাহমুদ

    Getting NullPointerException in GoogleApiClient.Builder(this).addApi(Plus.API, null) of Activity class.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this).addApi(Plus.API, null)
    .addScope(Plus.SCOPE_PLUS_LOGIN).build();
    // Any Help ?

    • harsg014

      first write these two lines….

      PlusOptions.Builder pl = PlusOptions.builder();
      PlusOptions options = pl.build();

      then replace “null” to “options” in the below statement…

      mGoogleApiClient = new GoogleApiClient.Builder(this)
      .addConnectionCallbacks(this)
      .addOnConnectionFailedListener(this).addApi(Plus.API, options)
      .addScope(Plus.SCOPE_PLUS_LOGIN).build();

      it’ll work now.

    • Mihir3646

      Just remove second parameter.

      mGoogleApiClient = new GoogleApiClient.Builder(this)
      .addConnectionCallbacks(this)
      .addOnConnectionFailedListener(this).addApi(Plus.API)
      .addScope(Plus.SCOPE_PLUS_LOGIN).build();

      it’ll work for me.

  • ravipatel

    Hello i try to run this app on my device but it give me error “unfortunatly G+ Login has stopped” please help me in this.

    • Bracebie

      It works for me just remove the second parameter (Plus.API, null) => (Plus.API)

      mGoogleApiClient = new GoogleApiClient.Builder(this)
      .addConnectionCallbacks(this)
      .addOnConnectionFailedListener(this).addApi(Plus.API)
      .addScope(Plus.SCOPE_PLUS_LOGIN).build();

  • anand

    Your tutorial is very useful for my view. but now am having my own created android apps. and your tutorial apps.. and how to open my apps via google plus account(gmail)..I dont have any idea to do this please help me……

  • abhishek

    Why aint there any login form ? I mean where will user enter his Google credentials..!

    • Marcus Vinicius Andreo Gabilhe

      The G+ log in takes care of it. If the user is already logged in with Google on his phone it just needs to press OK to log in. Otherwise the user will be taken to a inner browser window to sign in with google.

  • Tanakhon Kaewkunha

    I have run your code then logcat show this…

    java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.gpluslogin/info.androidhive.gpluslogin.MainActivity}: java.lang.NullPointerException: Null options are not permitted for this Api

  • Victor Wjugow

    love you, just that.
    Oh if anyone is using IDEA IntelliJ here’s how you add the google_play_services library : (create an empty project, and then add an Android module that will be your app, and then follow the first answer) http://stackoverflow.com/questions/17960315/importing-google-play-services-lib-into-intellij-idea-12-and-13

  • Silvester Moradu

    Thanks a lot……

  • Humayoon

    i want to login with google drive and also login with drop box in my android app bu i am a new in android developer how can i develop plzz hel meee

  • Sunny Sarser

    when i run the app ‘an internal error occured’ help me

    • Fayiz Fareed

      if u found solution pls mail me
      thnx

    • Mohd Ikram

      define your email id on developer console

  • appi24

    where you used client id in your app i cant see that

  • prasad Vdv

    I have downloaded ur code and tried
    Unfortunately G+Login, has been stopped

    and i tried copying the code in my app
    same error…!

    • There should be an error in LogCat.

      • prasad Vdv

        Unable to Start activityComponentinfo

        • The reason for the error will be somewhere in the log. Check for Caused by: line

          • Ankit Garg

            Hi Ravi,

            Thanks for the tutorial.

            I got NullPointerException for mConnectionResult which is called when g+ sign in button is clicked (resolveSigninError() method).

            How do we initialize it? I could see that it get’s initialized only in onConnectionFailed method.

  • Kamakshee

    i’m getting an error “Android library projects cannot be launched.” while running the project on AVD
    How am i suppose to deal with this error ?

    • You are not running the main project, you are running the library project. Right click on main project and run.

      Or you might marked the main project as library project. Right click -> properties -> android (on left) -> is Library (on right) – uncheck this.

  • Drew

    How would you do this using fragments? Such as in your fragments demo?

  • sagits

    Hi Ravi, awelsome tutorial. Nowadays you can get MD5 and SHA 1 fingerprint from debug key direct from eclipse > preferences > android > > build.

    • Yeah, that option is there from longtime back. Thanks for the info.

  • luis alberto

    I followed your tutorial but instead of clearing the activity i started another one withou having to hide the buttons, but i ran into the following problem:

    http://stackoverflow.com/questions/24562289/starting-an-activity-after-google-api-client-connect

  • PARVATHI

    I followed your tutorial .In my Google Plus Android Application com.android.google.gsm.plus.Plus;

    com.google.android.gms.common.api.ResultCallback;

    packages are not imported.please help mae What i will do

  • sandeep

    I am getting error as GoogleApiClient cannot be resolved to a type . also same error for SignInButton . Am i missing something ?

  • chaitanya

    Hey I have followed the tutorial and added G+ sign to my app. But I am unable to login …..it shows the following error “ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent” etc. I have no clue whay this error shows up. I have verified my package name sha1 key etc numerous times. But couldnt figure out the reason. Any help would grateful.

  • ACHIN VERMA

    Hi, the demo is running fine, but when i try to create New Client Id in Google API console i ‘m getting

    Duplicate fingerprint

    The signing fingerprint you specified is already used by another Android OAuth2 client.
    i don’t know who to fix this issue? even i have deleted all my project with it’s client Id but still i’m getting this error, please any one guide me

  • Francesca

    Hi Ravi, how can I take the profile pic and insert it in the navigation drawer? Thank you very much. Francesca

  • Tej Huded

    Hi i did all the above which you said, but then i get an internal error has occurred!! Im stuck @ this point i need some serious help!!

    • Hi Tej,

      Internal error occurs due several reasons. Search for “Google plus android internal error”. You will see few answers in stackoverflow

    • Fayiz Fareed

      if u not found solution just try this one

      this works for me

      mGoogleApiClient = new GoogleApiClient.Builder(this) ;// need three parameters
      .addApi(Plus.API, null); //remove null

      instead of above use below

      mGoogleApiClient = new GoogleApiClient.Builder(this,this,this)
      .addConnectionCallbacks(this)
      .addOnConnectionFailedListener(this)
      .addApi(Plus.API)
      .addScope(Plus.SCOPE_PLUS_LOGIN)
      .build();

    • ankit
      • vrajesh

        thank you so much its realy help..!

  • Ashish Tiwari

    Hi Ravi, I am unable to import these packages and classes:
    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
    import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
    import com.google.android.gms.common.api.ResultCallback;
    import com.google.android.gms.common.api.Status;

    What should I do?

    • I guess you haven’t added Play Services Library as mentioned in 4.2 step.

      • Jaldip katre

        I am having the same problem, The library is added still no luck..?

      • Ashish Tiwari

        I got the solution by updating the Google Play Service library. After updating I just remove the library from project and added again. Now Its working.

        • Yeah, I forgot to say update it first 🙂

          • Fernando Armando Bernal Marín

            Hello i have a same problem, executed step 4.2 this not resolve the problem, but i dont update the Google Play Service library i dont know execute this. please help me for resolved this problem, and sorry for any problem with my english i´m from México and my english not is good.

  • Ashish Tiwari

    I have added Play Service Library as you mentioned in 4.2 step, and I have added all permissions and meta tag also in Manifest File as you mentioned.

  • james grigg

    How can I save data about the loged in account. So that when they come back, i will be able to give them personalised data.

  • Samer Dawalib

    thanks for this awesome tutorial (the most complete one i’ve found so far), but i got a null pointer exception @

    mGoogleApiClient = new GoogleApiClient.Builder(this)

    .addConnectionCallbacks(this)

    .addOnConnectionFailedListener(this).addApi(Plus.API,null)

    .addScope(Plus.SCOPE_PLUS_LOGIN).build();

    //LogCat http://pastebin.com/ExcwmDDW

    • Lee Aehwa

      .addApi(Plus.API,null) -> .addApi(Plus.API)

      • Samer Dawalib

        thanks

  • james grigg

    I am being sent an error from Google Play Services API saying that:

    did not call through to “super.onPostCreate()”

    My Question on stack overflow: http://stackoverflow.com/questions/25293898/did-not-call-through-to-super-onpostcreate-when-using-google-play-services-a

  • Sarvesh SB

    Why this error – ” An internal error has occured ” ?

  • Dung Nguyen VN

    Can it work without ConnectionCallbacks andOnConnectionFailedListener?

  • Hi ravi why i always get

    08-28 23:37:38.557: E/AndroidRuntime(28591): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.foo.app/com.foo.app.LoginActivity}: java.lang.ClassNotFoundException: Didn’t find class “com.foo.app.LoginActivity” on path: DexPathList[[zip file “/data/app/com.foo.app-2.apk”],nativeLibraryDirectories=[/data/app-lib/com.foo.app-2, /vendor/lib, /system/lib]]

    ?
    this just happend when I intent to activity from this tutorial.

    thanks for your tutorial

    • this is my error from downloaded project of yours

      08-29 09:26:36.945: E/AndroidRuntime(3816): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{info.androidhive.gpluslogin/info.androidhive.gpluslogin.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “info.androidhive.gpluslogin.MainActivity” on path: DexPathList[[zip file “/data/app/info.androidhive.gpluslogin-2.apk”],nativeLibraryDirectories=[/data/app-lib/info.androidhive.gpluslogin-2, /vendor/lib, /system/lib]]

  • Marcos Campos

    Hi Ravi, error detected!

    09-03 21:56:57.015: E/AndroidRuntime(26306): Caused by: java.lang.NullPointerException: Null options are not permitted for this Api

  • Nathan

    Hi Ravi ,
    if i click G+ signin button it shows Toast as “An Internal error has occurred”.

  • Juliano Mendes

    Hi Ravi ,
    if i click G+ signin button it shows Toast as “An Internal error has occurred”.

    • Nihel

      same problem here can you please help me ?
      Thanks

    • Kiran Kumar

      All problems has solved…

      In the Consent window – fill up all the fields like email,product name and other optional fields (enter any URL like http://localhost ) enter the same URL(http://localhost) for product logo field. And don’t enter anything in GOOGLE+ Page field, leave as what is there and click save…
      Now run the app, it works fine …………..

  • Juliano Mendes

    Ravi, problem solved!

  • keith

    Thank your help !!! All problem were solved!!
    This is a good article so that help me solve Google Login problem 🙂

  • Android_Rocks

    every time when i click G+ signin button it shows Toast as “An Internal error has occurred”.
    please help me

    > and second thing , when you use g+ api, because only create not use client id or use not specify any where.
    > without client id google how to know which project through request comes.

    >please solve my problem fast as soon as possible.

    • VladMurray
    • Android_Rocks

      i solve internet error bug.
      first you use sign in apk file in android device and also use sign in apk sha1 certificate key
      not use cmd key its not working

      so please ravi update this tutorial .
      all the thing use shown its working

      THANKS Ravi Such a Great Tutorial
      its working great.

      • Pankaj Chauhan

        Sir please tell me how you solved this problem in simple words. Please sir.

        • Android_Rocks

          ok give me some time i can help you sure.

          • Android_Rocks

            Sorry For Delay ,

            one thing you change ,

            first step you must change :- SHA1 fingerprint

            click on this
            http://stackoverflow.com/a/17521584

            through this my problem solve

  • Nisha jain

    I got this error when i run this code :-

    java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.Button

    Please help me ,
    Thanks

    • harsha

      Plese use ImageView for ProfileImage class cast exception for while converting your image in button instead of button widget replace with imageview.

  • chaitu

    unfortunately g+login stopped..when I open app

    • chaitu

      worked after removing null here

      .addOnConnectionFailedListener(this).addApi(Plus.API,null)

      now getting internal error now

      • Chris Hieu

        I searched on StackOverFlow and can change code like this:
        mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this).addOnConnectionFailedListener(this)
        .addApi(Plus.API, new Plus.PlusOptions.Builder().build()) // note the options
        .addScope(Plus.SCOPE_PLUS_LOGIN).build();
        Ref: http://stackoverflow.com/questions/24481969/integrate-google-plus-android-error

  • Ankit

    Awesome tutorial Ravi. Thanks dude…

  • VladMurray

    Ensure You all fill out the consent section on Google Developer Portal Under APIs And Auths.

  • Nitin

    I tried to implement the code,but after clicking on sign in button a toast is coming saying internal error.while debugging it goes in onactivityresult’s and then goes into if (responseCode != RESULT_OK).Please help.

  • pkpdeveloper
  • Kamil

    Thanks Ravi, Awesome and complete tutorial. But how can I modify this to implement login without bugging my users with Google Plus? I have read, that google will shutdown other auth methods and only google+ will stay. There was also information, that users withoug google plus can log in too. But how to do it?

  • Thanks for this helpful tutorial. Really helped.

  • Chris

    Thank you very much. This is what I need.

  • Vito

    Thanks for this very helpful tutorial!!
    I need to log out of google plus from a different activity! Not the same activity which I use for login.
    Is it possible??

  • kuldeep kumar

    how to download the pdf file from google drive in android programatically in android i used many sample but not working correcly and my project deliver date is 19/11/2014 please give me some sample or any sugession please

  • Rajnish Vishwakarma

    Ravi Sir i m not getting where to put the client_secrets.json file..what is the use of it..and how to access it..Please tell.m sir…as in the above code there is no client_secrets.json file… please tell me..sir..

  • Paulo Basilio

    I get null person information

  • Ravish

    consent screen do not appear..

  • Genka Kasyan

    All did at shown in example. But have NullPointer. Have any idea??

    java.lang.NullPointerException

    at com.amazon.aws.CognitoSyncDemo.activity.GoogleActivity.resolveSignInError(GoogleActivity.java:105)

    at com.amazon.aws.CognitoSyncDemo.activity.GoogleActivity.signInWithGplus(GoogleActivity.java:253)

    at com.amazon.aws.CognitoSyncDemo.activity.GoogleActivity.onClick(GoogleActivity.java:234)

    at com.google.android.gms.common.SignInButton.onClick(Unknown Source)

    at android.view.View.performClick(View.java:4240)

    at android.view.View$PerformClick.run(View.java:17721)

    at android.os.Handler.handleCallback(Handler.java:730)

    at android.os.Handler.dispatchMessage(Handler.java:92)

    at android.os.Looper.loop(Looper.java:137)

    at android.app.ActivityThread.main(ActivityThread.java:5103)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:525)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

    at dalvik.system.NativeStart.main(Native Method)

  • Aaditya Sriram

    What is RESULT_OK ?

  • Jarvis

    Hi Ravi,
    I am able to connect to the login but when retirving the information its is saying person information null. Can you please help me with that. Also I want to retrieve the token that gets generated when the user gets logged in so if you have a tutorial for that also please share that.
    Thanks

  • Chitrita Ghosh

    Hi,

    I was getting this error java.lang.nullpointerexception.

    for that I replaced the below

    mGoogleApiClient = new GoogleApiClient.Builder(this)

    .addConnectionCallbacks(this)

    .addOnConnectionFailedListener(this).addApi(Plus.API, null)

    .addScope(Plus.SCOPE_PLUS_LOGIN).build();

    with

    mGoogleApiClient = new GoogleApiClient.Builder(this)

    .addConnectionCallbacks(this)

    .addOnConnectionFailedListener(this).addApi(Plus.API)

    .addScope(Plus.SCOPE_PLUS_LOGIN).build();

    Other than this It worked for me. The code was really helpful. Thanks

    • Carlos Suazo

      Change this
      .addOnConnectionFailedListener(this).addApi(Plus.API, null)

      for this
      .addOnConnectionFailedListener(this).addApi(Plus.API, Plus.PlusOptions.builder().build())

      let me know

    • 1ayushi .

      Thanks dear its working now

  • Vishnu Sharma

    Can i include two or more google plus apis with Single gmail address

  • Tushar Salvi

    your tutorial works great for me, but i m having 1 question how can i logout g+ from other activity

    • Pankaj Chauhan

      Brother is code running without any internal error?

      • Tushar Salvi

        yes, actually internal error cause when you inserting wrong package name in Google APIs console putting your package name from manifest.xml file it will work for sure

        • Pankaj Chauhan

          Thank you Tushar.

  • Pankaj Chauhan

    how to resolve internal error problem. Please help me.

    • piyush

      please check that have you developed client id or app id to resolve this error you have to develop a client id outh

  • Pankaj Chauhan

    Wooo yes man i run this code listen everybody this code is right to run it. First delete the null parameter from mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this).addApi(Plus.API)

    Second in this google developer console is not properly describe here the link
    https://developers.google.com/+/quickstart/android
    it help you.

  • Pankaj Chauhan

    Thank you very much Ravi sir for your code. can tell me how to fetch the contact of this user which we login with this code?

  • Parth Rajnai

    Hello, how to logout g+ from another activity..??
    i have tired to finding solution of it.

    • Keya

      Parth, you can store the GoogleApiClient in a Singleton class which can be accessed from another activity. I am doing so in my code. Else you can re-write the whole “GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();”

      And in the onConnect method, do the log out.

  • Akash KV

    mConnectionResult is null

    • Paranoiddroid

      I get that too

    • Guest

      Seems that onConnectionFalied need to before the resolveSignInError method…

    • stfleurs

      Did you find a solution for that!? let me know!

    • Rahul Jain

      mGoogleApiClient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API,null).addScope(Plus.SCOPE_PLUS_LOGIN).build();
      replace addApi(Plus.API,null)
      remove null
      addApi(Plus.API)
      it will be work 100 %

  • Redturbo5

    I have done all things in this tutorial, but there was some import that always error :

    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
    import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
    import com.google.android.gms.common.api.ResultCallback;
    import com.google.android.gms.common.api.Status;
    import com.google.android.gms.plus.Plus;

  • Shashank Kumar

    How do I get instance of GoogleApiClient on other Activities to access user info or logout user?
    How how can get its instance when we quit the application and relaunch again..thanks

  • vitrag

    Persona information is null…user is connected

  • ken

    do you know how to get other account information like birthday, gender..? i tried to use the available methods– getBirthday(), getGender(), but they didn’t work..

  • Sanwal

    Thanks for this nice tutorial sir, I am big fan of you,

    • I am glad that this tutorial helped you.

      • nhidi ghazi

        fuck ravi no one of your code work

  • javer

    I was wondering hoy do you post something in the wall using your app?

  • Pratik Borole

    Just tried the tut. App crashed after running. Null Pointer Exception at addOnConnectionFailedListener(this).addApi(Plus.API, null)

    please remove the null argument when initializing mGoogleApiClient – should be
    addOnConnectionFailedListener(this).addApi(Plus.API)

    definitely works now. The error occurred because Null options are not permitted for Google plus API.

    • Sahitya Kumar Suman

      Can you share your code

      on github or tell me how it can be romved because i tried almost all method to do so but not able to remove this error

      Thanx in advance

  • Alan

    Hey, Great tut, thanks for sharing.

    I want to know how can I open MainActivity after successful sign in with a G+ account.

    Thanks!
    Alan

  • Hung Nguyen

    Thanks for your tut. It helped me a lot.

  • vivek

    Hii i am a very big fan of you. i want to know how can i get list of circles
    please plese help

  • donraj

    I want to know if google plus login is secure rigorously:
    The situation is: “I make a user sign in, and then i get his email address from the api calls. Then I use ONLY the email address to do transactions on MY SERVER”.

    The question is: Can that be broken by a third party tweaked/rooted android, where the tweak tells my app that the person with email id=xyz@gmail.com is authenticated?

  • Mohammed Hayath

    Just pass on a single parameter in this manner.

    .addApi(Plus.API)

    instead of

    .addApi(Plus.API, null)

    you could also pass it a PlusOptions object

    .addApi(Plus.API, Plus.PlusOptions.builder().build())

    Either of these solutions will work

  • nabil

    hi…we are getting

    Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.example.abcd.MainActivity” on path: DexPathList[[zip file “/data/app/com.example.abcd-2.apk”],nativeLibraryDirectories=[/data/app-lib/com.example.abcd-2, /vendor/lib, /system/lib]]

    please help me…

  • Roel

    Nice copy of the official Google instructions

  • Amit Singh Tomar

    hello ,

    Please replace this code mGoogleApiClient = new GoogleApiClient.Builder(this)

    .addConnectionCallbacks(this)

    .addOnConnectionFailedListener(this).addApi(Plus.API)

    .addScope(Plus.SCOPE_PLUS_LOGIN).build();

    with

    mGoogleApiClient = new GoogleApiClient.Builder(this)

    .addConnectionCallbacks(this)

    .addOnConnectionFailedListener(this).addApi(Plus.API)

    .addScope(Plus.SCOPE_PLUS_PROFILE).build();

    and it will work fine .

    • HumaNature

      thanks. This is exactly what everyone above is needs.

  • sowmiya

    Hi Ravi,
    I am having an error. In the import statement,

    import com.google.android.gms.plus.Plus;
    The error is

    No libraries found for ‘com.google.android.gms.plus.Plus’.

    I am using Android Studio.
    Tell me how to proceed further.

    • aya zaki

      rightclick-properities-android-add->google service play
      then clean and build

  • Guest

    Hii Ravi,
    getting this error and not able to solve….
    java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.gpluslogin/info.androidhive.gpluslogin.MainActivity}: java.lang.NullPointerException: Null options are not permitted for this Api

    • Vijayakumar Natarajan

      Just pass on a single parameter in this manner.

      .addApi(Plus.API)

      instead of

      .addApi(Plus.API, null)

  • Ashish Tikarye

    Hiii Ravi,
    Project says…An internal error occured….

  • manoj kumar

    Same Error Me Also Getting An Internal Error Occured

  • yash

    Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) returns null

  • Mani Kandan

    googleplayseriveutil:the specified account could not be sign in.. what is error.. and i want to do for fix this???please help me out thanks in advance

    • Ujjwal Agrawal

      Hi Mani.. Even I was getting the same error and the reason was, I missed selecting the email address while filling the details in the consent screen….So I think you should once check the details that you have filled…This error may be due to incomplete information provided…Hope this may help..

  • hossam

    THAAAAAAAAAAAAANKSSS !!!!!!

  • Prathibha Nandini

    Again a Life saver Post… Hats Off Mr.Tamada..

  • asif ahmed

    I have updated my Google play services in extras as it said,removed null which was causing exception and now it fine when I run my app it shows a message that “your app won’t work unless you update Google play services”..

    and I got null pointer exception here:
    at com.google_sign.Google_main.resolveSignInError(Google_main.java:108)
    07-10 11:56:29.114: E/AndroidRuntime(19602):
    at com.google_sign.Google_main.signInWithGplus(Google_main.java:272)
    07-10 11:56:29.114: E/AndroidRuntime(19602):
    at com.google_sign.Google_main.onClick(Google_main.java:252)
    07-10 11:56:29.114: E/AndroidRuntime(19602):
    at com.google.android.gms.common.SignInButton.onClick(Unknown Source)

  • asif ahmed

    ok got it..whenever I run my app in a device or emulator ill get “your app wont work google play store need to be updated”,i have updated “Google APIs x86 (Google Inc.) – API Level 19” as target. Check “Use Host GPU”.Still I am getting the same message.

  • Kousik K

    how to retrive which user can access my account

  • Harish Chauhan

    Person information is null…user is connected. any suggestion or solution.

  • Sarathi Manivel

    I am using android studio. Google plus integration worked fine, but when i get the signed apk I get the following error message dialog “Error signing in the specified account. Please choose a different account”.

  • Jaye

    Can you display profile infomation in another activity and not on the same activity like what you did? If yes, how? which part should the new intent be called?

    • Store the information in shared preferences and in other activity just read the information and display it.

      Follow this article:
      http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/

      • Jaye

        I tried. Is it right that I call the activity in the onConnected function and erase the updateUI()?

        • Kumar Vivek

          I believe you could use Parse cloud to store user data and then fetch again back by get.currentuser();

          You will also be able to store the image or profile pic fetched in parse.

          • Jaye

            Does parse has a way of identifying different clients? Like you only want to send to select devices and not all? GCM has a registration id for every device?

          • Kumar Vivek

            Yes indeed it has, it uses the unique device id to identify, anyways every user account will have their own sessions. So you dont have to worry about it.

          • Jaye

            Thanks. I may be switching to Parse if my GCM implementtion still won’t work.

  • Monish Jayaraman

    Is this method Still working Ravi Tamanda or anyone?

    • Prashant Gupta

      Works for me.

  • sagar

    google + signin example is not working please fixed the bugs and update it.

  • Sindhu

    @ravi8x:disqus

  • Sindhu

    @ravi8x:disqus When I develop the same code it shows it is unfortunately stopped ..please let me know what the bug is!

    • Check the LogCat for errors. Give me the error report.

      • Aji

        Hi this is my logcat error when executing the same code.
        08-10 01:40:12.495: E/AndroidRuntime(1822): FATAL EXCEPTION: main
        08-10 01:40:12.495: E/AndroidRuntime(1822): Process: com.example.googleplusomo, PID: 1822
        08-10 01:40:12.495: E/AndroidRuntime(1822): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googleplusomo/com.example.googleplusomo.MainActivity}: java.lang.NullPointerException: Null options are not permitted for this Api
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.access$800(ActivityThread.java:144)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.os.Handler.dispatchMessage(Handler.java:102)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.os.Looper.loop(Looper.java:135)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.main(ActivityThread.java:5221)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at java.lang.reflect.Method.invoke(Native Method)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at java.lang.reflect.Method.invoke(Method.java:372)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
        08-10 01:40:12.495: E/AndroidRuntime(1822): Caused by: java.lang.NullPointerException: Null options are not permitted for this Api
        08-10 01:40:12.495: E/AndroidRuntime(1822): at com.google.android.gms.common.internal.zzu.zzb(Unknown Source)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at com.google.android.gms.common.api.GoogleApiClient$Builder.addApi(Unknown Source)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at com.example.googleplusomo.MainActivity.onCreate(MainActivity.java:82)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.Activity.performCreate(Activity.java:5933)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
        08-10 01:40:12.495: E/AndroidRuntime(1822): … 10 more

        • Léandre Charlebois

          try to change
          mGoogleApiClient = new GoogleApiClient.Builder(this)
          .addConnectionCallbacks(this)
          .addOnConnectionFailedListener(this)
          .addApi(Plus.API,null).addScope(Plus.SCOPE_PLUS_LOGIN)
          .build();

          with

          mGoogleApiClient = new GoogleApiClient.Builder(this)
          .addConnectionCallbacks(this)
          .addOnConnectionFailedListener(this)
          .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
          .build();

  • Aji

    Ravi Tamada This is what my logcat shows while running your code:

    08-10 01:40:12.495: E/AndroidRuntime(1822): FATAL EXCEPTION: main

    08-10 01:40:12.495: E/AndroidRuntime(1822): Process: com.example.googleplusomo, PID: 1822

    08-10 01:40:12.495: E/AndroidRuntime(1822): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googleplusomo/com.example.googleplusomo.MainActivity}: java.lang.NullPointerException: Null options are not permitted for this Api

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.access$800(ActivityThread.java:144)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.os.Handler.dispatchMessage(Handler.java:102)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.os.Looper.loop(Looper.java:135)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.main(ActivityThread.java:5221)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at java.lang.reflect.Method.invoke(Native Method)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at java.lang.reflect.Method.invoke(Method.java:372)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    08-10 01:40:12.495: E/AndroidRuntime(1822): Caused by: java.lang.NullPointerException: Null options are not permitted for this Api

    08-10 01:40:12.495: E/AndroidRuntime(1822): at com.google.android.gms.common.internal.zzu.zzb(Unknown Source)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at com.google.android.gms.common.api.GoogleApiClient$Builder.addApi(Unknown Source)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at com.example.googleplusomo.MainActivity.onCreate(MainActivity.java:82)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.Activity.performCreate(Activity.java:5933)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)

    08-10 01:40:12.495: E/AndroidRuntime(1822): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)

    08-10 01:40:12.495: E/AndroidRuntime(1822): … 10 more

  • Aji

    @ravi8x:disqus How can I create a separate activity for logout in google plus. Please help me ..

  • sriram veeraghanta

    Thank u very much

  • Udit Roy

    its crashing in my phone dont know y i just imported your project and linked with the library google service but still its not working

  • Tauseef Mamun

    Just pass on a single parameter in this manner.

    .addApi(Plus.API)

    instead of

    .addApi(Plus.API, null)

    to avoid crash

    http://stackoverflow.com/questions/23886586/google-for-android-getting-null-pointer

    • Parth Anjaria

      thank you this worked

  • Lou

    Can you use the logout method with gmail login?

  • Parth Anjaria

    Thank you so much
    can you help for facebook integration

  • Sok

    Such a breeze. Thanks a lot. Thanks author and thanks Google for making it nice and simple enough. Facebook login is a big PITA

  • diablo

    thank u…work properly……. after using .addApi(Plus.API) instead of .addApi(Plus.API,null)

  • Baldeep

    can I get user’s phone number and address after logging in

  • rahul rk

    The app runs but i am getting Unknown issue with Google Play services.

  • EB

    Thank you, Ravi. Works for me 100%

  • Raul Rodriguez

    Hello,

    I am following your tutorial.

    I have one question, what if I want to place the exit button in another activity? What code would be added in output activity?.

  • sheikh Muhammad Ashar Azam

    Sir how to get list of friends?

  • karthik

    Hi Ravi, am able to login but not display the user profile, showing person information is null.

  • sankar ganesh

    Unable to get Data: Status{statusCode=NETWORK_ERROR, resolution=null} … I am getting this error When accessing person information

  • vishal

    wher put the api for google plus

  • Owen Chen

    Dear Sir, I’ve followed your coded, and try to load personal profile,but get null

    Person me = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

    And the error : Error requesting visible circles: Status{statusCode=NETWORK_ERROR, resolution=null}

  • Sadhana

    when i run the application it gives a error message unfortunately stopped,please helpme to solve this

  • Sadhana

    when i select account for login it shows unknown issues with google play,please tell me the solution

    • Sujay Kumar

      may be you need to update the play services, or put the logs here for us to debug more.

      • Sadhana

        thank you

  • karthik

    Dear sir,
    As i was saw your sample but my question is how manage back end web api server to use this external authentication process.
    Please can you explain and i was use asp.net web api c#.

  • Hi,
    I tried this code and working correctly. But when I tried to integrate with my app, I get NullPointerException at mConnectionResult.hasResolution() method in resolveSignInError() method.
    Please help!

  • rishi

    Avoid passing null in addApi method, instead pass a single parameter i.e Plus.API

  • Dr John Parera

    Hii,
    I integrated google login in Android studio its working fine with login but i want to logout from another activity(SecondActivity) and it is asking for mGoogleClient(GoogleApiClient mGoogleClient) but GoogleApiClient is initialised in firstActivity so how can i get mGoogleClient without initialise again ??
    Thanks in advance

    • Michael

      please help

  • Coderz

    After clicking G+ signIn button, it displays all logged in Google accounts but after choosing one account, it shows nothing further. I m unable to find what’s wrong with it.
    I m working with android studio..
    Plz… make suggestion about it..

    • Hi am facing same issue ….. any solution so far ?

      • Pranay Deep

        Hi ,,I am also facing the same issue….any solution ?

        • your SHA1 fingerprint in Signing certificate fingerprint (SHA1) field is not right …. update it using console don’t be dependent on Eclipse or studio ….

    • Parth Vora

      I am getting the same issue, need help urgently….

  • Subin Babu

    downloading code shows no lib and EXIT …… Please help

    • include google play services lib in your project

    • Subin Babu

      Why this error – ” An internal error has occured ” ?

  • Shwetabh Singh

    Please update the post. unable to import com.google.android.gms.plus.Plus;(shows in red, cannot resolve symbol plus)
    How to show the profile picture name and email id in navigation drawer after log in

    (Android studio 1.5 with in build navigation drawer activity)

  • AndroidCuet

    i need google plus user’s contact list or friend list after sign in. is it possible?

  • After clicking G+ signIn button, it displays all logged in Google
    accounts but after choosing one account, it shows nothing further. I m
    unable to find what’s wrong with it.
    I m working with Eclipse ..
    Plz… make suggestion about it..

    • Saurabh Panchal

      did you solve this? I am facing same problem.

      • yes the issue i faced was due to the SHA1 fingerprint was not proper ….kindly look for debug.keystore in your .android folder ….i was generating my keystore using eclipse and faced the issue ….using command line i was able to generate the required one for api access in google console

    • ravi

      i am also facing same problam any solution

  • Subin Babu

    i face issue which, when the logout button press its blink and shows the same page (user data display page ). its not logut ?

  • swapnil patil

    i am facing the problem where it says that null option is not permitted for this API. what should i do?

  • Nidhi

    Hello Sir
    While running your app on emulator the app crashes and shows following error in Logcat…
    Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.example.test.MainActivity” on path: DexPathList[[zip file “/data/app/com.example.test-1.apk”],nativeLibraryDirectories=[/data/app-lib/com.example.test-1, /system/lib]]
    Please resolve it.

  • sumeet

    my some imports are not working like plus and api client plz help

  • Nagesh G

    Im implementing the above in fragments,,and it seems that onActivityResult() has not used anywhere and has error in that method

  • Perrito

    Who is with IdToken in SignIN google account?

  • raheez rahman

    first time it showed me a null pointer exception error at the api integrating part…and works finely after using addApi(Plus.API) instead of .addApi(Plus.API,null)

  • nikhil bhoyar

    when user login using google+ ,how to get and store his/her information in php, database .?

    • eliaszkubala

      You have to get information in android App, then pass these information to php and store it in SQL.

  • gattamaneni venkatanarasimham

    .addOnConnectionFailedListener(this).addApi(Plus.API) use instead of .addOnConnectionFailedListener(this).addApi(Plus.API,null)

  • Ranjan gupta

    hi dear please tell me get friends notification code please

  • ARASHI Funsho

    Hi Ravi! Just wanted to confirm how this is different from the normal Google Sign-in and also, is it still possible for a gmail not linked to google plus be signed in using this approach? Please reply soonest. Thank you!

    • ARASHI Funsho

      so I did found out it is possible, Plus makes it easier

  • dewi

    java.lang.nullPointerException at com.example.login.MainActivity.ResolveSigInError
    please help

  • kashif

    java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean com.google.android.gms.common.ConnectionResult.hasResolution()’ on a null object reference

    it shown error in{ if (mConnectionResult.hasResolution()) }

    private void resolveSignInError()
    {
    if (mConnectionResult.hasResolution()) {
    try {
    mIntentInProgress = true;
    mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
    } catch (IntentSender.SendIntentException e) {
    mIntentInProgress = false;
    googleApiClient.connect();
    }
    }
    }

    please help me out..

  • Chiranjib Ganguly

    String personGooglePlusProfile = currentPerson.getUrl();
    gives the link of profile, but i need circle friend list with email. can any one help me please …..

    • Check the updated article.

      • Chiranjib Ganguly

        Thank you for your reply. Can you share the link please,it will be Help full to me

        • It is the same article. I have modified the content and uploaded new code to download.

  • Mahen Sharma

    Its not responding after selecting google account,No error shown in logcat. handleSignInResult is always false.Can You help me out.

    • Anbu Mps

      Run your application by signing with release key and not debug key. If it doesn’t work still, export the apk and install the application to see if that works.

  • Anbu Mps

    Hi Ravi, I have a loginactivity with the same code as yours which opens up the tab activity with three fragments with one fragment containing the logout button. How do I call the signout method in the loginactivity from my fragment in tabactivity?

    • You can use Application class which creates singleton instance of mGoogleApiClient and add singOut() method. So that this method can be called from anywhere.

      mGoogleApiClient = new GoogleApiClient.Builder(this)
      .enableAutoManage(this, this)
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
      .build();

      Refer this tutorial to know how to use Application class to create Singleton instances.
      http://www.androidhive.info/2014/05/android-working-with-volley-library-1/

      • Anbu Mps

        Hi Ravi,

        Thanks for the reply. I triend using singleton as follows

        package com.bkno3.app;

        import android.app.Application;
        import android.content.SharedPreferences;
        import android.os.AsyncTask;
        import android.widget.Toast;

        import com.google.android.gms.auth.api.Auth;
        import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
        import com.google.android.gms.common.Scopes;
        import com.google.android.gms.common.api.GoogleApiClient;
        import com.google.android.gms.common.api.ResultCallback;
        import com.google.android.gms.common.api.Scope;
        import com.google.android.gms.common.api.Status;

        import org.json.JSONObject;

        import java.io.IOException;

        /**
        * Created by root on 12/09/16.
        */
        public class loginSingleton extends Application {

        private static loginSingleton mInstance = null;

        public GoogleApiClient mGoogleApiClient;

        SharedPreferences storeToken;

        private loginSingleton(){

        String stringUrl = “https://xxx.xxx.xxx”; //receiving client id from my api

        new getConfiguration().execute(stringUrl);

        }

        public static loginSingleton getInstance(){
        if(mInstance == null)
        {
        mInstance = new loginSingleton();
        }
        return mInstance;

        }

        private class getConfiguration extends AsyncTask {
        @Override
        protected String doInBackground(String… urls){
        try{
        WebRequest apiconn = new WebRequest();
        return apiconn.apiConnectionGet(urls[0]);
        } catch (IOException e){
        return “Unable to make the API call. Url may be invalid”;
        }
        }

        protected void onPostExecute(String result) {

        try {
        JSONObject reader = new JSONObject(result);
        String googleid = reader.getString(“GOOGLE_CLIENT_ID”);

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestScopes(new Scope(Scopes.PLUS_LOGIN)).requestServerAuthCode(googleid, false).requestEmail().build();
        mGoogleApiClient = new GoogleApiClient.Builder(loginSingleton.this).enableAutoManage(this/*FragmentActivity*/, this /*OnConnectionFailedListener*/).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();

        } catch (Exception e){

        }

        }
        }

        public void googleSignOut() {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
        new ResultCallback() {
        @Override
        public void onResult(Status status) {

        Toast.makeText(getApplicationContext(), “signedout”,Toast.LENGTH_LONG).show();
        }
        });
        }

        }

        And I am getting the following error

        Error:(66, 84) error: no suitable method found for enableAutoManage(loginSingleton.getConfiguration,loginSingleton.getConfiguration)
        method Builder.enableAutoManage(FragmentActivity,OnConnectionFailedListener) is not applicable
        (actual argument loginSingleton.getConfiguration cannot be converted to FragmentActivity by method invocation conversion)
        method Builder.enableAutoManage(FragmentActivity,int,OnConnectionFailedListener) is not applicable
        (actual and formal argument lists differ in length)

        Can you please see what’s the problem. been stuck at this for three days now and singleton seems to be the solution:)

        • Spoorthi

          Hi Ravi,

          I am getting this Error please give me the solution,

          D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
          E/FirebaseApp: Firebase API initialization failure.
          java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invoke(Native Method)
          at com.google.firebase.FirebaseApp.zza(Unknown Source)
          at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
          at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
          at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
          at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
          at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
          at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
          at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
          at android.app.ActivityThread.installProvider(ActivityThread.java:5174)
          at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769)
          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709)
          at android.app.ActivityThread.-wrap1(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5443)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
          Caused by: java.lang.IllegalAccessError: Method ‘void android.support.v4.content.ContextCompat.()’ is inaccessible to class ‘com.google.firebase.iid.zzg’ (declaration of ‘com.google.firebase.iid.zzg’ appears in /data/data/com.example.spoorthi.googlelogindemo5/files/instant-run/dex/slice-com.google.firebase-firebase-iid-9.0.0_ee47d05ea241573de5c2644f9ab718655108835e-classes.dex)
          at com.google.firebase.iid.zzg.zzeC(Unknown Source)
          at com.google.firebase.iid.zzg.(Unknown Source)
          at com.google.firebase.iid.zzg.(Unknown Source)
          at com.google.firebase.iid.zzd.zzb(Unknown Source)
          at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.google.firebase.FirebaseApp.zza(Unknown Source)
          at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
          at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
          at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
          at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
          at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
          at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
          at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
          at android.app.ActivityThread.installProvider(ActivityThread.java:5174)
          at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769)
          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709)
          at android.app.ActivityThread.-wrap1(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5443)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
          D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
          I/FA: App measurement is starting up, version: 9080
          I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
          D/FA: Debug logging enabled
          D/FA: AppMeasurement singleton hash: 68920031
          V/FA: Collection enabled
          V/FA: App package, google app id: com.example.spoorthi.googlelogindemo5, 1:453985369811:android:f374e31d160d9496
          V/FA: Registered activity lifecycle callback
          D/FirebaseApp: Initialized class com.google.android.gms.measurement.AppMeasurement.
          I/FirebaseInitProvider: FirebaseApp initialization successful
          V/FA: Using measurement service
          V/FA: Connecting to remote service
          V/GoogleSignatureVerifier: com.google.android.gms signature not valid. Found:
          MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMw
          EQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29n
          bGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDAeFw0wODA4MjEyMzEz
          MzRaFw0zNjAxMDcyMzEzMzRaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYw
          FAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5k
          cm9pZDEQMA4GA1UEAxMHQW5kcm9pZDCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAKtW
          LgDYO6IIrgqWbxJOKdoR8qtW0I9Y4sypEwPpt1TTcvZApxsdyxMJZ2JORland2qSGT2y5b+3JKke
          dxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjA
          sb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/Cx
          URaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJE
          qO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/T
          gt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYD
          VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIG
          A1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC
          4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/y
          zKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCE
          yj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1S
          KMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifK
          Z0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3Wf
          MBEmh/9iFBDAaTCK
          W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
          V/FA: onActivityCreated
          W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000015/n/armeabi-v7a
          W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000015/n/armeabi
          D/AutoManageHelper: starting AutoManage for client 0 false false
          D/AutoManageHelper: onStart true {0=com.google.android.gms.internal.zznr$zza@da5246d}
          D/GoogleSignInApiImpl: getSavedSignInResultIfEligible
          D/GoogleSignInApiImpl: trySilentSignIn
          D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
          V/FA: Activity resumed, time: 194163261
          I/Adreno: QUALCOMM build : 359b6d1, I14a17c7611
          Build Date : 12/04/15
          OpenGL ES Shader Compiler Version: XE031.06.00.02
          Local Branch : workspace
          Remote Branch :
          Remote Branch :
          Reconstruct Branch :
          I/OpenGLRenderer: Initialized EGL, version 1.4
          D/FA: Connected to remote service
          V/FA: Processing queued up service tasks: 1
          E/FA: Task exception on worker thread: java.lang.IllegalAccessError: Method ‘void android.support.v4.content.ContextCompat.()’ is inaccessible to class ‘com.google.firebase.iid.zzg’ (declaration of ‘com.google.firebase.iid.zzg’ appears in /data/data/com.example.spoorthi.googlelogindemo5/files/instant-run/dex/slice-com.google.firebase-firebase-iid-9.0.0_ee47d05ea241573de5c2644f9ab718655108835e-classes.dex): com.google.android.gms.measurement.internal.zzt.zzEd(Unknown Source)
          D/MainActivity: handleSignInResult:true
          E/MainActivity: display name: Spoorthi B
          D/AndroidRuntime: Shutting down VM
          E/AndroidRuntime: FATAL EXCEPTION: main
          Process: com.example.spoorthi.googlelogindemo5, PID: 10581
          java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String android.net.Uri.toString()’ on a null object reference
          at com.example.spoorthi.googlelogindemo5.MainActivity.handleSignInResult(MainActivity.java:111)
          at com.example.spoorthi.googlelogindemo5.MainActivity.access$200(MainActivity.java:28)
          at com.example.spoorthi.googlelogindemo5.MainActivity$3.onResult(MainActivity.java:182)
          at com.example.spoorthi.googlelogindemo5.MainActivity$3.onResult(MainActivity.java:178)
          at com.google.android.gms.internal.zznv$zza.zzb(Unknown Source)
          at com.google.android.gms.internal.zznv$zza.handleMessage(Unknown Source)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5443)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

      • Anbu Mps

        Hi Ravi,

        I implemented the Singleton as follows

        https://bitbucket.org/snippets/anbu_mps/EBkxX

        But getting the following error

        Error:(66, 84) error: no suitable method found for enableAutoManage(loginSingleton.getConfiguration,loginSingleton.getConfiguration)
        method Builder.enableAutoManage(FragmentActivity,OnConnectionFailedListener) is not applicable
        (actual argument loginSingleton.getConfiguration cannot be converted to FragmentActivity by method invocation conversion)
        method Builder.enableAutoManage(FragmentActivity,int,OnConnectionFailedListener) is not applicable
        (actual and formal argument lists differ in length)

  • Sanjeev Tagra

    Hi Ravi, I am facing a very weird issue. Login is working fine on most of the devices but on one device, even account picker is not showing up. after i press google login button, i do not get any response, neither any popup for picking account appears. Have you faced similar issue or any idea ?

    • Did you checked the logs. Also verify whether play services installed or not on that device.

      • Sanjeev Tagra

        Yes. Play services is available. After “startActivityForResult” is called, control doesn’t return.. “onActivityResult” is never called and account picker doesn’t appear as well. It is happening on one device – Mi 4i, Android – 5.0.2, MIUI Version – 8.0.1.0. Worst part is google login of other apps is working like Zomato & all.. What should i do ?

        • Is the apk provided in the article is working?

          http://download.androidhive.info/apk/google-plus-login.apk

          • Sanjeev Tagra

            Nops. This APK is not working as well. This is the standard code everyone is using. Even the official google documentation & github example has same code.

          • Sanjeev Tagra

            If you want, i can record the video of whats happening and share it to you. One more finding – found a similar device and login is working on that one. So, not an issue of Android Version.

          • I am not sure why. Ask question in stackoverflow.

          • Pulkit Kumar

            Having the exact same issue.. :

        • Pulkit Kumar

          Hey! I’m having the same issue.. Please tell me how to fix it? Thanks in advance.

  • Ben Zaaiman

    Hi Ravi,

    Our requirement is to share basic Android tablets (i.e. without Samsung Safe or Multiple Users enabled) between a succession of users while preserving privacy. Think about an internet cafe, but with tablets. We are wondering how to remove the previous user’s google account data from google apps like YouTube / Chrome.

    Can your methodology also log out users / clear user data from such apps (e.g. Chrome browser / YouTube) and … Skype (dare I ask?)

    If you can, maybe we can do some business. We don’t care about logging new users in; just about logging old users out.

    Ben

  • Harshit

    Getting this error how to solve this…

    FATAL EXCEPTION: main
    Process: gfxbandits.com.listingmodule, PID: 10594
    java.lang.NoSuchMethodError: No static method zzz(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzaa; or its super classes (declaration of ‘com.google.android.gms.common.internal.zzaa’ appears in /data/data/gfxbandits.com.listingmodule/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-9.4.0_a33aa404b944fe47b1a4ba53aadb71af9a156fc8-classes.dex)
    at com.google.android.gms.auth.api.signin.GoogleSignInOptions$Builder.(Unknown Source)
    at gfxbandits.com.listingmodule.LoginActivity.onCreate(LoginActivity.java:111)
    at android.app.Activity.performCreate(Activity.java:6010)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
    at android.app.ActivityThread.access$800(ActivityThread.java:155)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5343)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

  • Nawaz Khan

    Hi Ravi,
    I am facing a very weird issue. Login is working fine with already sync google account , but when i click on add account button from account picker it goes to add new account after that application is being crash, i do not get any response, Have you faced similar issue or any idea ?

    • I haven’t faced this problem. Are you finding any error in LogCat.

      • Nawaz Khan

        I manage the crash but my problem is that i don’t get all the data from newly added account
        e.g. i add new account and i got email address in getDisplayName() and also not getting profile pic URL and other information. But when i try that same account which was already sync in other device and try to login with that device it returns all data like DisplayName, Profile pic URL, etc.. that is my actual problem. please suggest me if u have any idea about it..

        • I don’t have correct idea dude. Please use stackoverflow to get help.

          • Nawaz Khan

            I search lot more about it but result is none.. that’s why i decided to ask you for help

          • Ok. I need to play with it.

          • Nawaz Khan

            Thanks dude… if you get any solution then let me know. I want to do this thing done as early as as possible.

  • Parth Parikh

    hi, i am getting the following error:
    Error:(198, 58) error: cannot find symbol variable loading
    Error:Execution failed for task ‘:app:compileDebugJavaWithJavac’.
    > Compilation failed; see the compiler error output for details.

  • Ashish saxena

    when i launch the activity then click on google button but that show gmail account we click on any account , them that show same page . and another click that will do not show any account. what i have to do

    • Muhammad Naveed

      Disable Email/Password enable only Google then try it will work fine

  • Satendra Kumar

    Hello Sir,
    its show the popup for choose account, if we choose any one then its don’t do any thing,

    • Mark Edison R. Cua

      It’s probably your configuration in google is incorrect (SHA-1, package name, etc) and also check if you copied the google-services.json in the right directory.

  • Mark Edison R. Cua

    Hi Ravi, you forgot to add in the manifest for the glide to work. Cheers!

  • RANDHIR SINGH

    Hi Ravi ,

    I created login with google successfully … and then control went to next home activity … and here I got problem,, there I have a logout option in navigation drawer menu of home activity and I tried all method to logout and getting control back to signin activity…. but unsuccessful. please help….

    • What is the function you are calling to logout?

  • Theebiga

    Hai Ravi,
    Can you help me to do the sign out from another activity? I tried several ways, It’s not working.

  • Afiq Angel

    hai ravi,

    Do you have any idea how i want to add progressbar after selecting the profile. Sometime, after choosing profile to login, it takes sometime to get the profile result, so.. i may need to put some loading bar.. thanks..

  • HP Software Technology

    I have tried to implement google plus login I have implemented push notification via firebase service and aslo need to implement the google+ login button but both services provide JSON file which has same name. What I should do please help me…

  • prakash jayapal

    Hi Ravi,

    During the new Account login rather than the existing one the App crashes, the error is

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String android.net.Uri.toString()’ on a null object reference

    while getting the Account picture it;s throwing the error can you please reply back with the suggestion.

    • Rachit Goyal

      May be your new google account does not contain image use acct.getPhotoUrl() != null ? acct.getPhotoUrl().toString() : null; in place of acct.getPhotoUrl().toString();

    • Saurav Singhal

      I am also facing same issue. please send me the solution of this issue

  • Hiren Gujarati

    hey ravi ,

    nice tutotrial i just loved it!!

    but would you please post login with google with multiple activities??

  • amit srivastava

    Please suggest me if I wanted to add multiple google accounts to my app and user can switch between accounts so app data will change according to the chosen account(just like in android gmail) how should I approach.
    I have implemented log in using single account.

  • Aman Jain

    Awesome (y) Code works ! But, I found a bug, it crashes when a user has No Google A/c image.
    So, I added
    try {
    String personPhotoUrl = acct.getPhotoUrl().toString();
    Glide.with(getApplicationContext()).load(personPhotoUrl)
    .thumbnail(0.5f)
    .crossFade()
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(imgProfilePic);
    }
    catch(Exception e){
    imgProfilePic.setImageResource(R.drawable.awkward);//awkward.png in drawable folder
    }
    updateUI(true);
    Now, No Problem.

    • Thanks.

    • UNNATI GANATRA

      hello, i tried implementing your changes but when i add this try catch block the variable personPhotoUrl used in the Log.e statement in the original code is not able to use the variable.

      To solve this i removed the variable declaration outside the try block still app gets crashed

    • Kumar Divya Singh PIET/CE/14/0

      Thanks this code helped me stop crashing my software.

  • shally woredon

    what about the fragment Ravi sir?

  • Sudeep Banerjee

    Does google will maintain the database of my app with above mentioned code?

  • Gaurav Gupta

    Hello Sir,
    I have implemented this and managed the code for logging out from another activity, it works fine.
    But when I upload app to play store, download and install it, I face app’s abnormal behaviour. I am not able to login, I am thrown to the logout section.
    Got any ideas what can be the cause of this?

    Also, I have recently updated my Moto G4 Plus to Android 7.0. And play store refuses to install my apps.
    What can be the reason?
    Any Clues??

  • kunal kumar
  • maulik togadiya

    code didn’t work when there is not any profile pic in google acc..plese help me

    • Abhishek kumar

      Glide.with(getApplicationContext())
      .load(personPhotoUrl)
      .placeholder(R.mipmap.ic_launcher) // for default image.
      .into(imgProfilePic);

  • Mehul

    I am getting null in

    acct.getPhotoUrl()
    in some devices (devices with marshmellow)

    please help me

  • Asad Mukhtar

    Code works after commenting some code but it is too laggy why?

  • Asad Mukhtar

    my app is login with google integration without internet access, How it is possible? reply me please i need to ask some more questions

  • Dharmesh Dhameliya

    Thanx. Code works. Can you help me to get friends circle list?

  • Praveen Kumar

    Code working fine. Your tutorials was awesome. I need some of the advance things

  • Gopal

    Hi Ravi,
    i have successfully generated the apk but when i click in the sign in button my accounts show up as in the first picture above but when i select my account then nothing happens. i cannot enter into the next UI. is there anything i need to change in manifest.xml?

  • kamal sharma

    Hi Ravi,

    Awesome tutorial for understanding google integration.

    But i am facing some issue while integration. when i clicked on Google Sign In Button it asked me to choose google account. On choosing the account i logged in successfully but i am getting your gmail data i.e. your name, your profile pic etc.

    • kamal sharma

      working fine. it is issue in nav bar header view

  • Abhishek kumar

    Awesome Tutorial, We need to add some more things during implementation.

    Add Internet Permission on menifest so that images will come.

    and use this for displaying images so if no Profile pic will come it will display default image.

    Glide.with(getApplicationContext())
    .load(personPhotoUrl)
    .placeholder(R.mipmap.ic_launcher) // for default image.
    .into(imgProfilePic);

  • Vishal Vekariya

    i download apk and install in redmi note 3 so success full login but i download code and install apk so not login please help me

  • Mayur Thole

    GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
    I am getting result as Status{statusCode=unknown status code: 12501, resolution=null}

    • A way from Away

      I also getting the same result. Is there anything wrong ?

      • Indirajith Blake

        Im also facing the same issue… Ravi can u help us????

  • Great post @ravi8x:disqus Is there a way to get the user cover photo, apart from the profile photo

  • Sagar Bhatnagar

    Sir,My app is crashing when I select a google account and log in, please help…

  • Sai Yadamreddy

    Hi Ravi Tamada,
    I am trying to integrate google plus in my app.before that I install in my phone your apk file in RedMi note 3, There is no response on signin click button.

    Thanks
    sai

  • Максим Алманов

    Can not resolve symbol ‘loading’ … what’s the problem?

  • Amit Verma

    Hi Sir, How should I add ggogle sevice.json file, If I have already added in my project for firebase, I am confuse how to implement this , please help me

    • You can’t have two google-services.json in one project. You can add an app into existing firebase console.

      • Amit Verma

        Thanku for reply sir, I have implemented

  • Ednecia Matlapeng

    great tutorial, thank you so much.

  • בני ויינר

    thank you, very nice

  • Ravi

    Hi Ravi,
    This tutorial is work fine but getting error on All Moto & Google Pixel devices.
    Error log:

    Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65636, result=-1, data=Intent { (has extras) }} to activity {in.co.ans.jalsounique/in.co.ans.jalsounique.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String android.net.Uri.toString()’ on a null object reference
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3787)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3830)
    at android.app.ActivityThread.access$1500(ActivityThread.java:166)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5541)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
    Caused by java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String android.net.Uri.toString()’ on a null object reference
    at in.co.ans.jalsounique.ProfileFragment.onGoogleAuthSignIn(ProfileFragment.java:386)
    at in.co.ans.jalsounique.googleSignIn.GoogleSignInHelper.onActivityResult(GoogleSignInHelper.java:86)
    at in.co.ans.jalsounique.ProfileFragment.onActivityResult(ProfileFragment.java:137)
    at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
    at android.app.Activity.dispatchActivityResult(Activity.java:6513)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3783)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3830)
    at android.app.ActivityThread.access$1500(ActivityThread.java:166)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5541)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)

    Please help to solve this.

    Thanks

    • appy fizz

      hi I am getting same error

      • Ravi

        Remove enableAutoManage(mContext, this) and add mGoogleApiClient.connect();

        as below:

        mGoogleApiClient = new GoogleApiClient.Builder(mContext)
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
        .build();
        mGoogleApiClient.connect();

        It’s work for me..

        • Govind

          Hi ravi,
          i am getting same error and also i removed enableAutoManage and add mGoogleApiClient.connect(); but still getting same error.
          What’s that mContext.. i am using (this) instead of (mContext)
          can you send your code..thank you

          it’s my project error log:
          FATAL EXCEPTION: main
          Process: com.example.govind.positiveapp, PID: 27319
          java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=7, result=-1, data=Intent { (has extras) }} to activity {com.example.govind.positiveapp/com.example.govind.positiveapp.GoogleSignIn}: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String android.net.Uri.toString()’ on a null object reference
          at android.app.ActivityThread.deliverResults(ActivityThread.java:3776)
          at android.app.ActivityThread.handleSendResult(ActivityThread.java:3819)
          at android.app.ActivityThread.access$1400(ActivityThread.java:159)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1433)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5507)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
          Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String android.net.Uri.toString()’ on a null object reference
          at com.example.govind.positiveapp.GoogleSignIn.handleSignInResult(GoogleSignIn.java:120)
          at com.example.govind.positiveapp.GoogleSignIn.onActivityResult(GoogleSignIn.java:167)
          at android.app.Activity.dispatchActivityResult(Activity.java:6520)
          at android.app.ActivityThread.deliverResults(ActivityThread.java:3772)
          at android.app.ActivityThread.handleSendResult(ActivityThread.java:3819) 
          at android.app.ActivityThread.access$1400(ActivityThread.java:159) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1433) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5507) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

  • Akash Reddy

    hi ravi thank you

  • krunal patel

    m not able to sign in when i generate signed APK
    can u pls give me solution of this?
    Thank u

  • shadab ahmed

    Thanks Ravi ,
    i have a problem , when i am choose any account after click sign in button, its does not gives any profile image and name .Log Value : handleSignInResult:false

    • Shailesh Diwakar

      @disqus_msg9hJJKFp:disqus i was facing same problem with this tutorial after that i figured out solution
      signed your apk by giving path of keystore used for generating SHA-1
      example : C:/User/.android/debug.keystore alias-name : androiddebugkey and store and keypass : android.Now run your signed released apk it will be working.

  • Nimzy Kevin Maina

    Hi Ravi,
    I have several Google emails account logged in on my phone. Some of them are just hosted by Gmail but are not really Gmail accounts (G-suite). I have noticed that when I use these email accounts to login, the app crashes.
    Is it that these accounts don’t have a G+ account? If so how do you handle such situations?

  • Rusmana Basyar

    Hello Ravi..
    How i integrated between FCM and googleplus sign in..

  • Shahzaib Dahani

    This is a great tutorial 🙂 I was wondering that if i can use navigation drawer so how will i update the users info in navigation java class, I mean if i am using loadnavHeader method so there i wont be able to get googleSignInResult object. I cant sort out how to update the users info on navigation drawer. I have followed your navigation drawer tutorial but there you are downloading the profile picture.

  • akansha sharma

    best tutorial it helps a lot ….and code is very simple to understand

  • randy wiratama

    can it is connect to database mysql ??
    I want this email saved to mysql..

    sorry for my english.

  • Christopher Kearns

    Thanks so much – with just a few tweaks, works great – Google Sign in for Android, et. al. not so much…
    Thanks again!

  • randy wiratama

    hi ravi,,
    I’m stuck at this..
    what the problem…?? can anybody help me ??

    https://uploads.disquscdn.com/images/40a855ba3fc06352183a9d6e98c467ff05f806df2d60d609a7b46d1b7bdc8686.png

    • vihar maravaniya

      application becomes forced close , your gmail does not have profile picture.

      he is not created perfect coding

  • aman

    hi ravi,
    what should i do to get accessToken..
    plz help…

  • sumit kumar

    if we dont use any image in our gmail account then the app stops..what to do

  • mithun

    hi am having the following issue in google signin

    java.lang.NoSuchMethodError: No virtual method zzait()Ljava/util/ArrayList; in class Lcom/google/android/gms/auth/api/signin/GoogleSignInOptions; or its super classes (declaration of ‘com.google.android.gms.auth.api.signin.GoogleSignInOptions’ appears in /data/app/com.example.billitonservices.appname-1/base.apk:classes7.dex)

    please help me out.

  • rahmad nafiul

    hi ravi
    great tutorials and working fine
    is this tutorial can be connect to database mysql ?
    thank you

  • Raj Gar

    Inactivity, disconnecting from the service – getting this error

  • varun v nair

    Hi Ravi sir, would you suggest a way to transfer the result to another activity which has a navigation drawer and this activity is used to display the user profile…please help.. 🙂

  • lun L

    Sir, can you also do login with facebook tutorial like this tutorials? thank you

  • Alok Dwiivedi

    This one is goole sign in not google plus sign in

  • varun v nair

    Sir, I need one more help. I am using sign out button in another activity, so i want to pass mGoogleApiClient value how can i achieve this. I tried it using Intents but its not working.