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 an addAccount() 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 to addAccount from
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