4

when i move my testapp to the sdcard, my custom account-authenticator (com.heidi.AccountStuff) not exist anymore.

if i would add a new account like this

Account account = new Account("heidi", AccountAuthenticatorService.TYPE);
AccountManager accountManager = AccountManager.get(this);
accountManager.addAccountExplicitly(account, "", null);

it will thrown a RuntimeException

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

ok, make sense, beacause when i output the authenticatortypes (with following code snippet):

    for(AuthenticatorDescription d: accountManager.getAuthenticatorTypes()) {
        Log.d("add", d.toString());
    }

it will output

AuthenticatorDescription {type=com.htc.linkedin}
AuthenticatorDescription {type=com.htc.android.mail.eas}
AuthenticatorDescription {type=com.htc.sync.provider.weather}
AuthenticatorDescription {type=com.htc.android.windowslive}
AuthenticatorDescription {type=com.htc.android.mail}
AuthenticatorDescription {type=com.htc.stock}
AuthenticatorDescription {type=com.htc.lucy.account}
AuthenticatorDescription {type=com.google}

after moving the app back to the internal store, my custom type displaying in the output, like this:

AuthenticatorDescription {type=com.heidi.AccountStuff}
AuthenticatorDescription {type=com.htc.linkedin}
AuthenticatorDescription {type=com.htc.android.mail.eas}
AuthenticatorDescription {type=com.htc.sync.provider.weather}
AuthenticatorDescription {type=com.htc.android.windowslive}
AuthenticatorDescription {type=com.htc.android.mail}
AuthenticatorDescription {type=com.htc.stock}
AuthenticatorDescription {type=com.htc.lucy.account}
AuthenticatorDescription {type=com.google}

any ideas?

silly
  • 7,789
  • 2
  • 24
  • 37
  • 1
    Check these links : http://stackoverflow.com/questions/3774282/securityexception-caller-uid-xxxx-is-different-than-the-authenticators-uid & http://stackoverflow.com/questions/8508748/log-all-user-accounts-and-passwords – VVB Jul 31 '14 at 11:31
  • 1
    Print value of uid/account name+password for sd card & local storage. I think it treats as a different app while moving app between local to sd & vice versa – VVB Jul 31 '14 at 11:32

1 Answers1

3

There are few parts to implement custom account...

To invoke AccountManager in your Activity, something like that you already implemented...

  Account account = new Account(username, ACCESS_TYPE);
  AccountManager am = AccountManager.get(this);
  Bundle userdata = new Bundle();
  userdata.putString("SERVER", "extra");

  if (am.addAccountExplicitly(account, password, userdata)) {
   Bundle result = new Bundle();
   result.putString(AccountManager.KEY_ACCOUNT_NAME, username);
   result.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCESS_TYPE);
   setAccountAuthenticatorResult(result);
  }

In res/xml/authenticator.xml you have to define your AccountAuthenticator data (responsible for your Authenticator UID). ACCESS_TYPE have to be the same string as your defined accountType in this xml!

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="de.buecherkiste"
android:icon="@drawable/buecher"
android:label="@string/app_name"
android:smallIcon="@drawable/buecher" >
</account-authenticator>

Finally you have to define your service your Manifest. Please do not forget the relevant permissions for manage your accounts (AUTHENTICATE_ACCOUNTS / USE_CREDENTIALS / GET_ACCOUNTS / MANAGE_ACCOUNTS)

<service android:name="AuthenticatationService">

<intent-filter>
    <action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
    android:resource="@xml/authenticator" />

</service>
Vaishali Sutariya
  • 5,093
  • 30
  • 32