Android: How to get username in Google Play Games

Asked

Viewed 77 times

2

I’m developing a game and after the player does the sign in is redirected to another in-game activity. My problem is that I don’t know how to get the username of him in that activity in which he enters after the Sign In. I have to do it again Sign In in the second activity?

I tried to do this:

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

but what you gave me back was: com.google.candroid.gms.auth.api.signin@ and I want the username his.

Does anyone know how to get the username?

1 answer

2


Opa, blza?

Use the GoogleSignIn.getLastSignedInAccount method to request information about the currently connected user profile.

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 learn more, access the documentation: https://developers.google.com/identity/sign-in/android/people

  • Thank you! It worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.