before I start, I want to emphasize that I read some answers and they don't help me. Like:
addAccountExplicitly throws IllegalStateException caused by Securityexception
SecurityException: caller uid XXXX is different than the authenticator's uid ...
like the title suggestes, I am trying to use AccountManager in an Activty under Application (not Service), but without sucess. I use an 4.3 emulator (Intel image). I can easly liist all accounts on the emulator (added via android interface) but when I want to create one an Error comes in:
09-14 13:21:21.863: E/AndroidRuntime(3291): java.lang.SecurityException: caller uid 10046 is different than the authenticator's uid
09-14 13:21:21.863: E/AndroidRuntime(3291): at android.os.Parcel.readException(Parcel.java:1431)
09-14 13:21:21.863: E/AndroidRuntime(3291): at android.os.Parcel.readException(Parcel.java:1385)
09-14 13:21:21.863: E/AndroidRuntime(3291): at android.accounts.IAccountManager$Stub$Proxy.addAccountExplicitly(IAccountManager.java:719)
09-14 13:21:21.863: E/AndroidRuntime(3291): at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:612)
Here are my quick code snippets:
Login.java ->
public class Login extends AccountAuthenticatorActivity {
...
protected void onCreate(Bundle savedInstanceState) {
...
AccountManager accountmanager = AccountManager.get(this);
Account userAccount = new Account(“Test”, “test.activities”);
if (accountmanager.addAccountExplicitly(userAccount, “pass”, null))
System.out.println(“Added success”);
else System.out.println(“Added failed”);
}
...
}
res/xml/authenticator.xml
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="test.activities"
android:icon="@drawable/ic_launcher"
android:smallIcon="@drawable/ic_launcher"
android:label="@string/app_name"
/>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxxx"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name="Application"
android:allowBackup="true"
android:icon="@drawable/cg_icon_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
...
</application>
</manifest>
Tried it on 2.2 Android phone and the error is the same. I can succesfully list all the Accounts although (with Account[] accounts = accountmanager.getAccounts();). I also tried this app https://play.google.com/store/apps/details?id=com.udinic.accounts_example and can add the account with it. But via my application, no success.