Unable to select different account on google login for android

不羁的心 提交于 2020-07-18 05:49:27

问题


I have implemented Google Signing for Android app. The user can successfully login from the Google Login Button.

This screen appears while selecting a Social Account : 1

So now the user has logged in successfully by selecting his/her account.

Now, user logs out and tries to sign in again by using Google Login Button.

At this time, he is not asked with the option to choose account , he is automatically logged in using the account he/she selected at the first time.

At the time of logout what should I do to clear the cache of selected account.


回答1:


As you didn't provide any code or reference how you are logging in and logging out, it might be that you incorrectly sign out user from the app.

So here is what docs describe one should do on user logout: https://developers.google.com/identity/sign-in/android/disconnect

Sign out:

Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    // ...
                }
            });

Note: You must confirm that GoogleApiClient.onConnected has been called before signing out.

Also check status which comes in onResult - maybe there is some error, which might lead to the answer.




回答2:


try using this method to log out from Google sign in:

Make sure u call it after u successfully get logged in onConnected(Bundle arg0)

 public void Disconnect_google() {
    try {
        if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
                    mGoogleApiClient.clearDefaultAccountAndReconnect().setResultCallback(new ResultCallback<Status>() {

                        @Override
                        public void onResult(Status status) {

                            mGoogleApiClient.disconnect();
                            Toast.makeText(getApplicationContext(),"Disconnected",Toast.LENGTH_SHORT).show();
                        }
                    });

                }  
    } catch (Exception e) {
        Log.d("DISCONNECT ERROR", e.toString());
    }
}



回答3:


At the time of logout when you are login from google then use below code

if (mGoogleApiClient.isConnected()) {
                             Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                            mGoogleApiClient.disconnect();
                            mGoogleApiClient.connect();
                        }



回答4:


GoogleSignInOptions gso = new GoogleSignInOptions.
                Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).
                build();

        GoogleSignInClient googleSignInClient= GoogleSignIn.getClient(this,gso);
        googleSignInClient.signOut().addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()){
                    FirebaseAuth.getInstance().signOut(); // very important if you are using firebase.
                    Intent login_intent = new Intent(getApplicationContext(),YouLoginActivity.class);
                    login_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); // clear previous task (optional)
                    startActivity(login_intent);
                }
            }
        });



回答5:


When you login using google it will show all the signin google account in the device. when you select any one than it proceed further but when you logout from your system and login it again. it directly choose the previous account.

so for choosing from all existing account in device you have to clear the app data.

for clearing app data follow below steps 1. go to device settings 2. choose APPs 3. select your app 4. storage/clear data



来源:https://stackoverflow.com/questions/42338045/unable-to-select-different-account-on-google-login-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!