问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/54367277/android-get-username-in-google-play-games