gpt4 book ai didi

java - 如何检查 Android 设备上的 Google Play 游戏帐户是否可用?

转载 作者:行者123 更新时间:2023-11-30 10:49:47 25 4
gpt4 key购买 nike

我想知道在 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 游戏 帐户可用 herehere ,如果用户使用 Google 帐户登录,它本身就可用,因此我们的第一种方法是:

  1. 检查是否有 Google 帐户登录
  2. 检查该用户是否登录 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();
}

您也可以只使用 BaseGameUtilsPlay Games Services APIs .this link 中有一些如何实现它的示例.

关于java - 如何检查 Android 设备上的 Google Play 游戏帐户是否可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35302514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com