5

I am writing a GMail client for Android. I want to list all GMail accounts in a ListView. When the user clicks one item, I want the program to retrieve the password of the corresponding account.

However, I get a SecurityException:

java.lang.SecurityException: caller uid 10107 is different than the authenticator's uid

This is my code:

AccountManager accountManager = AccountManager.get(context);

this.username = account.name;
this.password = accountManager.getPassword(account); //this is where I get the exception

I have all these permissions in AndroidManifest.xml:

<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

According to Android reference, the only permission needed should be MANAGE_ACCOUNTS.

What is the problem of my code?

4

1 回答 1

4

您可以获取 authtoken,但无法获取用户的实际凭据。实际的贷项只能由创建它们的应用程序访问。从 getPassword 方法的文档(强调我的):

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

于 2011-10-03T19:39:08.587 回答