简体   繁体   中英

How can I have all existing users sign out from Google when updating the app?

I am trying to integrate Google Play Game Services into my app. (I am really having trouble with it so please take a look at this question as well..) And I actually have been using Google Sign In which uses Web Client ID and trying to switch it to Google Play Games which uses Android Client ID.

What I want to know is having every users sign out when the user updates the app. Otherwise if the user already signed in using web client id and try to use Google Play Games functionality, app crashes.

How can I handle this problem?

EDIT : You need to a create Splash Activity which will initially check for the Build Version

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM