I am trying to remove a custom account in AccountManager.
This is my code :
final Handler handler = new Handler ();
AccountManagerCallback<Boolean> callback = new AccountManagerCallback<Boolean>()
{
@Override
public void run(AccountManagerFuture<Boolean> arg0)
{
String test = "test";
}
};
AccountManagerFuture<Boolean> bool = am.removeAccount(account, callback, handler);
Permissions I'm using :
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"></uses-permission>
The account is never removed and the callback never called, any idea ? No trace in logs
android.accounts.AccountManager. This class provides access to a centralized registry of the user's online accounts. The user enters credentials (username and password) once per account, granting applications access to online resources with "one-click" approval.
Accounts Manager app can be used to track your daily income and expense transaction as per your need. Easy Entries: Account Manager App is easy in adding, deleting and canceling a credit or debit entry.
Using an AccountManager to store credentials is a much secure way than storing in a file or a SQL DB. A file can be retrieved by any other app unlike via AccountManager Android will enforce that only your app will be able to access to the key.
Had the same problem
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP_MR1) {
accountManager.removeAccount(account, {}, AContext.app.mainHandler)
} else {
accountManager.removeAccountExplicitly(account)
}
For API 22 and higher works perfectly, but on API 19 didn't work at all.
Finally found the problem in my implementation of AbstractAccountAuthenticator:
override fun getAccountRemovalAllowed(response: AccountAuthenticatorResponse?, account: Account?): Bundle {
AccountHelper.removeAccount()
return super.getAccountRemovalAllowed(response, account)
}
It became to work after deleting "AccountHelper.removeAccount()"
I don't know - maybe it'll help
Try this it will work
// Global Variables
public static final String AUTHORITY = "com.example.package";
public static final String ACCOUNT_TYPE = "com.example.package";
public static final String ACCOUNT = "my_custom_account_name";
// Account Manager definition
AccountManager accountManager = (AccountManager) this.getSystemService(ACCOUNT_SERVICE);
// loop through all accounts to remove them
Account[] accounts = accountManager.getAccounts();
for (int index = 0; index < accounts.length; index++) {
if (accounts[index].type.intern() == AUTHORITY)
accountManager.removeAccount(accounts[index], null, null);
}
requires
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With