我正在尝试开发一款游戏,用户在 Play Games
中登录
后会被转发到另一个Activity
。但在第二个 Activity
中,我不知道如何获取他的用户名
。我是否需要再次登录
(这次是在第二个 Activity
上)才能获取它?
我尝试过
GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).toString();
但它返回类似com.google.candroid.gms.auth.api.signin@
的内容,我想要的是他在Play games
中的用户名,而不是这个。
我正在读这篇文章solution但在这里我必须再次创建一个新的 GoogleApiClient
才能获取它。
最佳答案
使用 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
关于Android:在 Google Play 游戏中获取用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54367277/