2

I'm trying to develop a game where the user after sign in in Play Games is forwarded to another Activity. But on this second Activity I don't know how to get his username. Do I have to Sign in again (this time on the second Activity) to obtain it?

I tried with

GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).toString();

but it returns something like com.google.candroid.gms.auth.api.signin@ and I what I want is his username in Play games, not this.

I was reading this solution but here I've got to create a new GoogleApiClient again to get the it.

porthfind
  • 1,581
  • 3
  • 17
  • 30

1 Answers1

2

Use the GoogleSignIn.getLastSignedInAccount method to request profile information for the currently signed in user.

GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(getActivity());
if (acct != null) {
  String personName = acct.getDisplayName();
  String personGivenName = acct.getGivenName();
  String personFamilyName = acct.getFamilyName();
  String personEmail = acct.getEmail();
  String personId = acct.getId();
  Uri personPhoto = acct.getPhotoUrl();
}

To find out more, go to the official documentation: https://developers.google.com/identity/sign-in/android/people