2
我想知道是否有已註冊爲Google Play遊戲帳戶的Android設備上有可用的帳戶。如何檢查Android設備上是否提供Google Play遊戲帳戶?
我正在使用Java和LibGDX。
任何想法?
我想知道是否有已註冊爲Google Play遊戲帳戶的Android設備上有可用的帳戶。如何檢查Android設備上是否提供Google Play遊戲帳戶?
我正在使用Java和LibGDX。
任何想法?
編輯: 谷歌玩遊戲不再需要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!
在這種情況下,開發商具體請求的範圍爲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帳戶登錄,則可用,因此我們的第一種方法是:
要檢查的Android設備具有谷歌用戶登錄:
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+使用者登錄。
你可以嘗試使用谷歌的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中有幾個如何實現它的示例。
非常感謝您的詳細解答。我使用BaseGameUtils。但是,如果用戶確實擁有Google+,但尚未登錄,會發生什麼情況?我還有第二個問題:當用戶還沒有Google+帳戶時,是否有必要啓動Google Play遊戲?我認爲這可能會嚇跑不喜歡使用Google+的用戶。 – Z0q
@ Z0q這些都是非常好的後續問題!所以我找到了一個Android開發者帖子,表示不再需要Google+。我已經用信息編輯了我的答案。 http://android-developers.blogspot.com/2016/01/play-games-permissions-are-changing-in.html –
@ Z0q如果你只是想刪除簽名邏輯或修改,我' D推薦你檢查這個問題:http://stackoverflow.com/questions/22046530/how-can-i-make-the-play-game-services-not-automatically-sign-in-at-the-startup –