I ran into a lot of similar problems.  Some notes for anyone seeking
to implement an authenticator.

Three details that I took away:

1.  Your login activity has to invoke
AccountManager.addAccountExplicitly before the account is created
(even though the Android debug claims to have created it).  I'd
assumed the account was created behind the scenes through my response
call.  I was wrong.
2.  Your auth and sync service defs have to include the magic
attributes: android:exported="true" android:process=":XXX" (where XXX
is auth and contacts, respectively).
3.  If you don't at least define a no-op sync adapter, then the
accounts & sync settings page from setup will crash causing Android to
reboot (occurring in 2.0, probably related to
http://code.google.com/p/android/issues/detail?id=4721).

The following resources were extremely helpful:

http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
http://github.com/c99koder/AndroidSyncProviderDemo/blob/master/res/xml/contacts.xml

On Jan 24, 9:00 am, Brion Emde <[email protected]> wrote:
> It turns out that my account is being added, at least according to
> this trace from logcat:
>
> D/AddAccount(   58): account added: Bundle
> [{accountType=com.example.bloa, authto
> ken=WEbDlp4trjR3ajXPGn0GthNqrhPAUaJ6gWaKEAo0, authAccount=20341230-
> xRIt1kiGskNUW
> AsUYyRA0nw39p0ZlmKeUXr5jQfvp}]
>
> That is the correct information. I am intending to to have the
> authAccount be the User's OAUTH token and the authtoken be the User's
> OAUTH secret. It seems that the infrastructure is claiming that an
> account has been created in the AccountManager. Yet it does not show
> up in the list of Accounts in Accounts & Sync settings. This is after
> I did an Add Account to my authenticator on that settings page.
>
> When I try to calladdAccountfrom within the same package as the
> Authenticator, it does not work at all, as described above, dying with
> a "bind failure".
>
> I saw this same thing in a thread about AccountManager from November
> and that seemed to have ended up in a defect. I'm pretty sure I'm not
> seeing the same thing they were. One of them was getting a similar
> message that his account had been added that I am getting. Yet, no
> accounts are found, either in that list or programatically.
>
> On Jan 23, 9:12 am, Brion Emde <[email protected]> wrote:
>
>
>
> > I've researched the earlier threads about AccountManager and still am
> > having problems. I'm trying to extend my Twitter OAUTH demo to use the
> > AccountManager. I've built the beginnings of a class based on
> > AbstractAccountAuthenticator and a Service that seems to do what it is
> > supposed to do.
>
> > My Authenticator does get installed on a 2.1 Emulator. I can see it
> > when I go to the Accounts & Sync Settings app. If I click on Add
> > Accounts and then on My Authenticator, I go through the OAUTH process,
> > with an Activity being fired off (by the Account Manager?) from the
> > KeyIntent that the authenticator returns. The authentication process
> > proceeds and the Activity fields the redirection from the browser in
> > its onNewIntent() function (it's a SingleInstance activity).
> > Everything appears to be working and the Activity returns its results
> > the way it seems it is supposed to. The problem is, the new account
> > never shows up in the Accounts list on the Accounts & Sync page.
>
> > My second problem is that I also have an Activity in the application
> > that contains the authenticator. When I try to do anaddAccount() from
> > that activity, which is my original demo tiny Twitter client, I get a
> > very succinct bind failure of my service to the AccountManager.
>
> > So, when I run the Authenticator from the Accounts & Sync Settings
> > page, it all works, except the new account isn't showing up. When I
> > try to run the Authenticator from my Activity which is in the same
> > package, I get a bind failure.
>
> > Now I'll document how I'm returning the result in the Activity, which
> > is derived from AccountAuthenticatorActivity:
>
> >   �...@override
> >     public void onNewIntent(Intent i) {
> >             Bundle b = new Bundle();
> >         String verifier;
> >             try {
> >                 Uri data = i.getData();
> >                 if(data == null || (verifier = data.getQueryParameter
> > (OAuth.OAUTH_VERIFIER)) == null) {
> >                                 b.putInt(AccountManager.KEY_ERROR_CODE, 
> > -10000);
> >                                 
> > b.putString(AccountManager.KEY_ERROR_MESSAGE, getString
> > (R.string.auth_error));
> >                                 mResponse.onError(-10000, 
> > getString(R.string.auth_error));
> >                 } else {
> >                                 mProvider.retrieveAccessToken(verifier);
> >                             String token = mConsumer.getToken();
> >                             String secret = mConsumer.getTokenSecret();
> >                             b.putString(AccountManager.KEY_ACCOUNT_NAME, 
> > token);
> >                             b.putString(AccountManager.KEY_ACCOUNT_TYPE, 
> > getString
> > (R.string.auth_type));
> >                             b.putString(AccountManager.KEY_AUTHTOKEN, 
> > secret);
> >                             mResponse.onResult(b);
> >                 }
> >                 } catch (OAuthMessageSignerException e) {
> >                         b.putInt(AccountManager.KEY_ERROR_CODE, -1);
> >                         b.putString(AccountManager.KEY_ERROR_MESSAGE, 
> > e.getMessage());
> >                         mResponse.onError(-1, e.getMessage());
> >                         e.printStackTrace();
> >                 } catch (OAuthNotAuthorizedException e) {
> >                         b.putInt(AccountManager.KEY_ERROR_CODE, -2);
> >                         b.putString(AccountManager.KEY_ERROR_MESSAGE, 
> > e.getMessage());
> >                         mResponse.onError(-2, e.getMessage());
> >                         e.printStackTrace();
> >                 } catch (OAuthExpectationFailedException e) {
> >                         b.putInt(AccountManager.KEY_ERROR_CODE, -3);
> >                         b.putString(AccountManager.KEY_ERROR_MESSAGE, 
> > e.getMessage());
> >                         mResponse.onError(-3, e.getMessage());
> >                         e.printStackTrace();
> >                 } catch (OAuthCommunicationException e) {
> >                         b.putInt(AccountManager.KEY_ERROR_CODE, -4);
> >                         b.putString(AccountManager.KEY_ERROR_MESSAGE, 
> > e.getMessage());
> >                         mResponse.onError(-4, e.getMessage());
> >                         e.printStackTrace();
> >                 }
> >             setAccountAuthenticatorResult(b);
> >         finish();
> >     }
>
> > And here is the short stack trace I get when I try toaddAccountfrom
> > my Activity, rather than through the Accounts & Sync page:
>
> > W/System.err(  264): android.accounts.AuthenticatorException: bind
> > failure
> > W/System.err(  264):    at
> > android.accounts.AccountManager.convertErrorToExcepti
> > on(AccountManager.java:1096)
> > W/System.err(  264):    at android.accounts.AccountManager.access$500
> > (AccountMan
> > ager.java:74)
> > W/System.err(  264):    at android.accounts.AccountManager$AmsTask
> > $Response.onEr
> > ror(AccountManager.java:944)
> > W/System.err(  264):    at android.accounts.IAccountManagerResponse
> > $Stub.onTrans
> > act(IAccountManagerResponse.java:69)
> > W/System.err(  264):    at android.os.Binder.execTransact(Binder.java:
> > 287)
> > W/System.err(  264):    at dalvik.system.NativeStart.run(Native
> > Method)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to