Android 从帐户管理器中删除帐户

Android 从帐户管理器中删除帐户,android,accountmanager,Android,Accountmanager,我尝试使用此代码删除帐户,但它不起作用: { AccountManager accMgr = AccountManager.get(getApplicationContext()); Account[] accounts = accMgr.getAccountsByType(AccountGeneral.ACCOUNT_TYPE); for (Account ac : accounts) { accMgr.removeAccount(ac, null, n

我尝试使用此代码删除帐户,但它不起作用:

{
    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;
    }

有什么问题吗?

答案是这一行

accMgr.getAccountsByType(AccountGeneral.ACCOUNT_TYPE);
在这里,我按类型获取帐户,这是错误的,我必须获取所有帐户并循环以删除它,因此答案是用getAccounts替换此行

{

                    AccountManager accMgr = AccountManager.get(getApplicationContext());
                    Account[] accounts = accMgr.getAccounts();
                    for (Account ac : accounts) {
                        accMgr.removeAccount(ac, null, null);
                    }
            }