Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I delete the accounts and sync in Android phone programmatically?

Tags:

android

I am developing a project which needs to remotely delete the accounts and sync such as Facebook, Twitter, Dropbox and so forth... Is this possible to be done through programming? Need opinions from you guys...

Thanks.

like image 740
Android_Rookie Avatar asked Sep 25 '12 15:09

Android_Rookie


1 Answers

Yes it can be done using the AccountManager and the removeAccount method.

First get an instance of the AccountManager:

AccountManager am = AccountManager.get(this);

Then get a list of all accounts on the device:

Account[] accounts = am.getAccounts();

Once you've chosen which account(s) you want to remove (for this example we'll just use the first), call removeAccount on them:

if (accounts.length > 0) {
    Account accountToRemove = accounts[0];
    am.removeAccount(accountToRemove, null, null);
}

You can use the 2nd parameter of the removeAccount method to supply a callback to be called once the account has been removed (removing an account is an asynchronous operation).

like image 85
Joseph Earl Avatar answered Oct 11 '22 12:10

Joseph Earl