Android: Get username in Google Play Games

可紊 提交于 2019-12-11 09:36:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!