Get user email information after onConnected callback in google

173 Views Asked by At

I am using GoogleApiClient to authorize user in my app.

Building google api client using:

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

// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(context)
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
        .enableAutoManage(this, this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();

My activity definition:

public class UserLoginActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener 

Since enableAutoManage is used, app automatically logs in and gives a callback to onConnected method.

@Override
public void onConnected(@Nullable Bundle bundle) {
    // todo - how to get emailid here of already authorised user?
    verifyUserAndLaunchNextActivity();
}

Inside this onConnected callback, bundle has null value. Now, how do I get emailId of the already authorised user? Any chance I can get it from mGoogleApiClient?

P.S Other threads in SO are based on GooglePlus API which is deprecated. Please answer this based on new GoogleApiClient.

0

There are 0 best solutions below