Android自定义账号找回密码

Android custom account retreive the password

我已经根据文档创建了一个自定义帐户,我有一个 class 扩展 AbstractAccountAuthenticator 和服务。

我添加这样的帐户:

    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");
        }
    }

一切正常,帐户显示在设置中。

我的问题是:

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

看来 AccountManager#getPassword(Account account) 正是您所需要的。

您也可以通过管理器的 getAccounts 方法获取您的 Account 对象