【问题标题】:Android: Get username in Google Play GamesAndroid:在 Google Play 游戏中获取用户名
【发布时间】:2019-01-25 14:29:56
【问题描述】:

我正在尝试开发一个游戏,其中在Play Games 中的sign in 之后的用户被转发到另一个Activity。但是在这第二个Activity 我不知道如何得到他的username。我是否必须再次Sign in(这次是在第二个Activity)才能获得它?

我试过了

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

但它返回类似com.google.candroid.gms.auth.api.signin@ 的内容,而我想要的是他在Play games 中的用户名,而不是这个。

我正在阅读这个solution,但在这里我必须再次创建一个new GoogleApiClient 才能得到它。

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    使用GoogleSignIn.getLastSignedInAccount 方法请求当前登录用户的个人资料信息。

    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();
    }
    

    如需了解更多,请前往官方文档:https://developers.google.com/identity/sign-in/android/people

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 2015-10-03
      • 2015-11-11
      相关资源
      最近更新 更多