【发布时间】:2016-05-20 01:20:29
【问题描述】:
我想知道在 Android 设备上是否有可用的帐户注册为 Google Play 游戏帐户。
我正在使用 Java 和 LibGDX。
有什么想法吗?
【问题讨论】:
标签: java android libgdx google-play-services google-play-games
我想知道在 Android 设备上是否有可用的帐户注册为 Google Play 游戏帐户。
我正在使用 Java 和 LibGDX。
有什么想法吗?
【问题讨论】:
标签: java android libgdx google-play-services google-play-games
编辑: Google Play 游戏不再需要 here 中提到的 Google+ 帐户
问题:要求不必要的范围
// Don’t do it this way!
GoogleApiClient gac = new GoogleApiClient.Builder(this, this, this)
.addApi(Games.API)
.addScope(Plus.SCOPE_PLUS_LOGIN) // The bad part
.build();
// Don’t do it this way!
在这种情况下,开发人员专门请求 plus.login 范围。如果您要求 plus.login,您的用户将获得同意 对话框。
解决方案:只询问您需要的范围
// This way you won’t get a consent screen
GoogleApiClient gac = new GoogleApiClient.Builder(this, this, this)
.addApi(Games.API)
.build();
// This way you won’t get a consent screen
从您的 GoogleApiClient 构造中删除任何不需要的范围 以及您不再使用的任何 API。
原答案:
当用户使用here 和here 提到的Google+ 帐户登录时,Google Play 游戏 帐户可用,并且该帐户本身可用如果用户使用 Google 帐户登录,那么我们的第一种方法是:
要检查 Android 设备是否有 Google 用户登录:
public boolean isLoggedInGoogle() {
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
for (Account account : list) {
if (account.type.equalsIgnoreCase("com.google")) {
return true;
}
}
return false;
}
现在,检查 Android 设备是否有 Google+ 用户登录。
您可以尝试使用 Google API 客户端启动登录序列,如 question 中所述:
private GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
您也可以只使用Play Games Services APIs 的BaseGameUtils。 this link 有几个实现方法的示例。
【讨论】:
I would like to know if there is an account available on an Android device which is registered as a Google Play Games account.。您告诉我如何查看该帐户是否为 Google 帐户,但我如何知道它是否也注册了 Google Play 游戏?