我尝试使用此代码删除帐户,但它无效:
{
AccountManager accMgr = AccountManager.get(getApplicationContext());
Account[] accounts = accMgr.getAccountsByType(AccountGeneral.ACCOUNT_TYPE);
for (Account ac : accounts) {
accMgr.removeAccount(ac, null, null);
}
}
即使我在我的身份验证器中有这个代码:
@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) throws NetworkErrorException {
Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
return result;
}
出了什么问题?
答案 0 :(得分:1)
答案是这一行
accMgr.getAccountsByType(AccountGeneral.ACCOUNT_TYPE);
在这里,我按错误的类型获取帐户,我必须获取所有帐户并循环删除它,因此答案是用 getAccounts()
替换此行{
AccountManager accMgr = AccountManager.get(getApplicationContext());
Account[] accounts = accMgr.getAccounts();
for (Account ac : accounts) {
accMgr.removeAccount(ac, null, null);
}
}