我想知道在 Android 设备上是否有可用的帐户注册为 Google Play 游戏帐户。
我正在使用 Java 和 LibGDX。
有什么想法吗?
最佳答案
编辑: Google Play 游戏不再需要上述的 Google+ 帐户 here
问题:要求不必要的范围
// 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!
In this case, the developer is specifically requesting the plus.login scope. If you ask for plus.login, your users will get a consent dialog.
解决方案:只询问您需要的范围
// 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
Remove any unneeded scopes from your GoogleApiClient construction along with any APIs you no longer use.
原答案:
当用户使用提到的 Google+ 帐户登录时,Google Play 游戏 帐户可用 here和 here ,如果用户使用 Google 帐户登录,它本身就可用,因此我们的第一种方法是:
- 检查是否有 Google 帐户登录。
- 检查该用户是否登录 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();
}
您也可以只使用 BaseGameUtils的 Play Games Services APIs . this link 中有一些如何实现它的示例.
关于java - 如何检查 Android 设备上的 Google Play 游戏帐户是否可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35302514/