gpt4 book ai didi

java - 更新应用时如何让所有现有用户退出 Google?

转载 作者:行者123 更新时间:2023-12-02 01:23:14 26 4
gpt4 key购买 nike

我正在尝试将 Google Play 游戏服务集成到我的应用中。 (我真的遇到了麻烦,所以请也看看 this question ..)实际上我一直在使用使用 Web 客户端 ID 的 Google Sign In 并尝试将其切换到使用 Android 客户端 ID 的 Google Play 游戏.

我想知道的是,当用户更新应用程序时,让每个用户都退出。否则,如果用户已使用网络客户端 ID 登录并尝试使用 Google Play 游戏功能,应用将会崩溃。

我该如何解决这个问题?

最佳答案

编辑:您需要创建一个 Splash Activity,它将首先检查构建版本

Create a Splash Activity and add this method to it.

        public class SplashScreen extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
forcedLogout();
}
},5*1000);
}
}

private void forcedLogout(){

if (myPrefs.getLong(PREF_APP_CURRENT_VERSION,0) != BuildConfig.VERSION_CODE){
//call logout method
}else{
startActivity(new Intent(SplashScreen.this,MainActivity.class));

finish();
}
}

then add shared preferences in your login activity.

SharedPreferences.Editor prefEditor = myPrefs.edit();
prefEditor.putLong(PREF_APP_CURRENT_VERSION,BuildConfig.VERSION_CODE);
prefEditor.commit();

关于java - 更新应用时如何让所有现有用户退出 Google?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57331056/

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