Android 检测从Google Play UI注销
我的游戏目前正在使用菜单中的登录和注销按钮,以便使用Google Play排行榜/成就。不幸的是,用户也可以从Google Play UI注销,但GameHelper.isSignedIn()在通过Google的UI注销时仍然返回true。当用户以这种方式注销后试图查看排行榜或成绩时,游戏崩溃Android 检测从Google Play UI注销,android,google-play-games,achievements,Android,Google Play Games,Achievements,我的游戏目前正在使用菜单中的登录和注销按钮,以便使用Google Play排行榜/成就。不幸的是,用户也可以从Google Play UI注销,但GameHelper.isSignedIn()在通过Google的UI注销时仍然返回true。当用户以这种方式注销后试图查看排行榜或成绩时,游戏崩溃 有人知道一种更新的方法来检查用户是否通过UI注销吗?我说已更新,因为我在stackoverflow中看到一些线程不起作用。我创建了一个名为登录游戏的成就,并尝试在onSingIn()上解锁它 在屏幕的re
有人知道一种更新的方法来检查用户是否通过UI注销吗?我说已更新,因为我在stackoverflow中看到一些线程不起作用。我创建了一个名为登录游戏的成就,并尝试在onSingIn()上解锁它 在屏幕的resize事件中,其中是我的登录按钮,我实现了以下代码:
@Override
public void resize(int width, int height) {
//...
if(game.gameHelper.isSignedIn()){
if (!game.gameHelper.unlockAchievements()){
game.gameHelper.forceSignOut();
}
}
}
forceSignOut()是在GameHelper类上实现的
public void forceSignOut() {
if (mGoogleApiClient != null){
mGoogleApiClient.disconnect();
}
}
最后在BaseGameActivity中:
protected void forceSignOut(){
mHelper.forceSignOut();
}
别忘了实现您的GameServiceInterface:
public void forceSignOut();
我只是跟着
一切正常。
它正在使用
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();
}
}
}
检查我的可能重复,它仍然有效-我刚刚在Google Play服务的最新版本(6.1.71(1501030-038))上测试了它。谢谢,我对它做了一些更改,删除了RequestCode if(resultCode==GamesActivityResultCodes.RESULT_重新连接_必需){gameHelper.disconnect();}else{gameHelper.onActivityResult(请求代码、结果代码、数据);}
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();
}
}
}