问题描述
我正在尝试开发一个游戏,将Play Games
中sign 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.
我正在阅读,但是在这里,我必须再次创建一个new GoogleApiClient
来获取它.
推荐答案
使用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游戏中获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!