我的遊戲目前正在使用菜單中的登錄和註銷按鈕,以便使用Google Play排行榜/成就。不幸的是,用戶也可以從Google Play用戶界面註銷,但通過Google的用戶界面,GameHelper.isSignedIn()仍然會返回true。當用戶嘗試檢查排行榜或成就後用戶退出這種方式,遊戲崩潰。檢測從Google Play UI註銷
有誰知道更新的方式來檢查用戶是否通過UI註銷?我說更新,因爲我已經看到了幾個線程在stackoverflow不起作用。
我的遊戲目前正在使用菜單中的登錄和註銷按鈕,以便使用Google Play排行榜/成就。不幸的是,用戶也可以從Google Play用戶界面註銷,但通過Google的用戶界面,GameHelper.isSignedIn()仍然會返回true。當用戶嘗試檢查排行榜或成就後用戶退出這種方式,遊戲崩潰。檢測從Google Play UI註銷
有誰知道更新的方式來檢查用戶是否通過UI註銷?我說更新,因爲我已經看到了幾個線程在stackoverflow不起作用。
我創建了一個名爲Sign in Play Games的成就,並嘗試在onSingIn()上解鎖它。
@Override
public boolean unlockAchievements() {
boolean r = true;
if (gameHelper.isSignedIn()){
try{
Games.Achievements.unlock(gameHelper.getApiClient(), getString(R.string.achievement_sign_in_play_games));
}
catch(Exception ex){
r = false;
}
finally{
}
}
else{
r = false;
}
return r;
}
屏幕上的resize事件哪裏是我的登錄按鈕,我實現了這個代碼:
@Override
public void resize(int width, int height) {
//...
if(game.gameHelper.isSignedIn()){
if (!game.gameHelper.unlockAchievements()){
game.gameHelper.forceSignOut();
}
}
}
的forceSignOut()是在GameHelper類實現
在BaseGameActivity最後:
protected void forceSignOut(){
mHelper.forceSignOut();
}
不要忘記實現你GameServiceInterface:
public void forceSignOut();
我只是跟着https://developers.google.com/games/services/training/signin ,一切工作正常。 它使用
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false; // set to true when you're in the middle of the
// sign in flow, to know you should not attempt
// to connect in onStart()
GoogleApiClient mGoogleApiClient; // initialized in onCreate
@Override
protected void onStart() {
super.onStart();
if (!mInSignInFlow && !mExplicitSignOut) {
// auto sign in
mGoogleApiClient.connect();
}
}
@Override
public void onClick (View view) {
if (view.getId() == R.id.sign_out_button) {
// user explicitly signed out, so turn off auto sign in
mExplicitSignOut = true;
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
}
}
的可能重複【如何處理來自谷歌遊戲服務斷開?(http://stackoverflow.com/questions/26162684/how-to-handle-disconnect-from-google-game - 服務) – free3dom 2014-10-11 22:10:15
看看我的[答](http://stackoverflow.com/questions/26162684/how-to-handle-disconnect-from-google-game-services/26186889#26186889),仍然有效 - 我只是在最新版本的Google Play服務(6.1.71(1501030-038))上進行測試。 – free3dom 2014-10-11 22:12:05
謝謝,我改變了一下,刪除了RequestCode if(resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED){ \t gameHelper.disconnect(); \t} else { \t \t gameHelper.onActivityResult(requestCode,resultCode,data); \t} – 2014-10-12 03:54:31