如何从Android手机上已配置的电子邮件中检索密码

apa*_*tki 1 android accountmanager

我正在尝试检索Google帐户的密码,但出现安全异常。

我也已授予androidManifest.xmlaccount_manager,aunthenticator,get_account,管理帐户的权限。

android.accounts.Account[] googleAccount =
AccountManager.get(mContext).getAccounts();
for (android.accounts.Account account: googleAccount ) {
String pwd = AccountManager.get(mContext).getPassword(account);
AccountManager.get(mContext).setPassword(account, null);
}
Run Code Online (Sandbox Code Playgroud)

Flo*_*Flo 5

getPassword()的文档说:

此方法要求调用方持有权限AUTHENTICATE_ACCOUNTS,并具有与帐户的身份验证器相同的UID。

我认为句子的最后一部分对您来说很重要。您正在尝试获取尚未为其编写身份验证器的帐户的密码。身份验证器定义如何对特定服务进行身份验证。仅允许身份验证器或使用相同UID的应用程序调用getPassword()方法。通过这一限制,可以确保没有人可以窃取用户的帐户凭据。