如何检查 Google Play 游戏帐户是否在 Android 设备上可用?
How to check whether Google Play Games account available on Android device?
我想知道 Android 设备上是否有可用的帐户注册为 Google Play 游戏帐户。
我正在使用 Java 和 LibGDX。
有什么想法吗?
编辑:
Google Play Games 不再需要如上所述的 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 and 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 of the Play Games Services APIs。
在 this link.
中有一些如何实现它的示例
我想知道 Android 设备上是否有可用的帐户注册为 Google Play 游戏帐户。
我正在使用 Java 和 LibGDX。
有什么想法吗?
编辑: Google Play Games 不再需要如上所述的 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 and 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 of the Play Games Services APIs。 在 this link.
中有一些如何实现它的示例