![](/img/trans.png)
[英]How do I enable Google sign-in for my Android app such that it only allows users from a specific Google domain?
[英]How can I have all existing users sign out from Google when updating the app?
我正在嘗試將Google Play游戲服務集成到我的應用中。 (我確實遇到了麻煩,所以也請看一下這個問題 。)實際上,我一直在使用使用Web客戶端ID的Google登錄,然后嘗試將其切換到使用Android客戶端ID的Google Play游戲。
我想知道的是讓每個用戶在用戶更新應用程序時退出。 否則,如果用戶已經使用Web客戶端ID登錄並嘗試使用Google Play游戲功能,則應用程序將崩潰。
我該如何解決這個問題?
編輯 :您需要創建一個初始啟動時會檢查生成版本的啟動活動
創建一個Splash Activity並將此方法添加到其中。
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();
}
}
然后在您的登錄活動中添加共享的首選項。
SharedPreferences.Editor prefEditor = myPrefs.edit();
prefEditor.putLong(PREF_APP_CURRENT_VERSION,BuildConfig.VERSION_CODE);
prefEditor.commit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.