androidaccounts

Android custom account retreive the password


I've created a custom account according to doc, i have a class extending AbstractAccountAuthenticator and the service.

I add an account like this:

    public static void addCustomAccount(Context context, String title, String password) {
        AccountManager accountManager = AccountManager.get(context);
        Account account = new Account(title, Constants.ACCOUNT_KEY);
        if (accountManager.addAccountExplicitly(account, password, null)) {
            Log.v(Constants.LOGTAG, "Account in Android Accounts was created");
        }
    }

Everything works perfectly, the account is displayed in the settings.

My question is:

How can i retreive the password i've set in this procedure?


Solution

  • Seems like AccountManager#getPassword(Account account) is what you need.

    And you can get your Account object via the getAccounts method of the manager as well