views:

1001

answers:

3

I've seen AccountManager in the android SDK, and can see it is used for storing account information, but I can't find any general discussion of what it is intended for.

Anyone know of any helpful discussions of what the intention behind AccountManager is and what it buys you

Any opinions of what type of Accounts this is suitable for? Would this be where you'd put your user's account information for a general web service?

Regards

Phil

+4  A: 

From http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/:

The first piece of the puzzle is called an Account Authenticator, which defines how the user’s account will appear in the “Accounts & Sync” settings. Implementing an Account Authenticator requires 3 pieces: a service that returns a subclass of AbstractAccountAuthenticator from the onBind method, an activity to prompt the user to enter their credentials, and an xml file describing how your account should look when displayed to the user. You’ll also need to add the android.permission.AUTHENTICATE_ACCOUNTS permission to your AndroidManifest.xml.

Macarse
That's a good article, but do you think the AccountManager is only for accounts that sync contacts and email, or can/should we use it for anything that has user IDs and passwords?
Phil
@Phil: I've never used AccountManager so I can't tell you. Remember that this comes with 2.0 so if you are willing to run on devices with lower SDK you will have to find another way to handle login.
Macarse
A: 

It may be wrong place to log my query, but its urgent. can anyone please help me how to 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 authenticator");
            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 bieng thrown which is handled at lower layer.

parul
A: 

Hi, in my previuos post, came to know we cant use AccountManagerService. Therefore using account manager. i need help to delete accounts which are displayed in “account and sync” from my app.

i’m trying with this code: AccountManager accountManager = (AccountManager)mContext.getSystemService(Context.ACCOUNT_SERVICE); android.accounts.Account[] accounts = AccountManager.get(mContext).getAccounts(); for (android.accounts.Account account: accounts) { AccountManager.get(mContext).removeAccount(account, null, null); }

but i’m getting accounts = 0 i.e. no accounts. whereas accounts exist. It would be great help if u can suggest something to resolve my problem.

parul
Parul this is indeed the wrong place for your question. Ask a separate question. You will get much more views and answers.
Janusz