-->

How to forcefully remove Google default selected A

2019-08-22 01:15发布

问题:

I am trying to remove default selected account from gmail api when logout from app in android.

this is GoogleAccountCredential function to establish connection of gmail account.

GoogleAccountCredential  mCredential = GoogleAccountCredential.usingOAuth2(
                getApplicationContext(), Arrays.asList(AppController.SCOPES))
                .setBackOff(new ExponentialBackOff());

回答1:

Gmail API doesn't Provide And default account select method you can just call this method to select account when required

startActivityForResult(
        mCredential.newChooseAccountIntent(),
        REQUEST_ACCOUNT_PICKER);

just remember to pass null to mCredential when logout



回答2:

I was tired also, but I have found the solution; If google account is already login after remove default selected account from Gmail API. follow this step...

 SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit();
 editor.putString(PREF_ACCOUNT_NAME, null);
 editor.commit(); 

update the value of preferences from particular Key "PREF_ACCOUNT_NAME"

~Thanks