Android: how to delete account from database which are displayed under "accounts and sync" from my own application
How can I delete google accounts from "accounts and sync"? I'm trying to call this line my app:
AccountManagerService.getSingleton().onServiceChanged(null,true);
whereas onServiceChanged() method is defined in AccountManagerService.java.
public void onServiceChanged(AuthenticatorDescription desc, boolean removed) {
boolean accountDeleted = false;
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Cursor cursor = db.query(TABLE_ACCOUNTS,
new String[]{ACCOUNTS_ID, ACCOUNTS_TYPE, ACCOUNTS_NAME},
ACCOUNTS_TYPE + "=?", new String[]{desc.type}, null, null, null);
try {
while (cursor.moveToNext()) {
final long accountId = cursor.getLong(0);
final String accountType = cursor.getString(1);
final String accountName = cursor.getString(2);
Log.d(TAG, "deleting account " + accountName + " because type "
+ accountType + " no longer has a registered authe开发者_StackOverflow中文版nticator");
db.delete(TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null);
accountDeleted = true;
}
} finally {
cursor.close();
if (accountDeleted) {
sendAccountsChangedBroadcast();
}
}
This piece of code is not doing anything. I feel exception is being thrown which is handled at lower layer.
Try AccountManager.removeAccount.
精彩评论