Android:在Google Play游戏中获取用户名 [英] Android: Get username in Google Play Games

查看:185
本文介绍了Android:在Google Play游戏中获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个游戏,将Play Gamessign in之后的用户转发到另一个Activity.但是在第二个Activity上,我不知道如何获得他的username.是否需要再次Sign in(这次是第二个Activity)来获取它?

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?

我尝试过

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

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

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.

我正在阅读推荐答案

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

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

要了解更多信息,请访问官方文档: https://developers.google.com/identity/sign-in/android/people

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

这篇关于Android:在Google Play游戏中获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆