【问题标题】:How to forcefully remove Google default selected Account in Gmail API?如何在 Gmail API 中强制删除 Google 默认选择的帐户?
【发布时间】:2018-05-22 13:27:34
【问题描述】:
我正在尝试从 android 中的应用程序注销时从 gmail api 中删除默认选择的帐户。
这是建立 gmail 帐户连接的 GoogleAccountCredential 函数。
GoogleAccountCredential mCredential = GoogleAccountCredential.usingOAuth2(
getApplicationContext(), Arrays.asList(AppController.SCOPES))
.setBackOff(new ExponentialBackOff());
【问题讨论】:
标签:
android
gmail
gmail-api
google-account
【解决方案1】:
我也很累,但我找到了解决办法;如果从 Gmail API 中删除默认选择的帐户后,谷歌帐户已经登录。按照这个步骤...
SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit();
editor.putString(PREF_ACCOUNT_NAME, null);
editor.commit();
从特定键“PREF_ACCOUNT_NAME”更新首选项的值
~谢谢
【解决方案2】:
Gmail API 不提供默认帐户选择方法,您可以在需要时调用此方法来选择帐户
startActivityForResult(
mCredential.newChooseAccountIntent(),
REQUEST_ACCOUNT_PICKER);
请记住在注销时将 null 传递给mCredential