Still wants an authTokenType (not Account.type). Here's what I tried:
final AccountManager accountManager = AccountManager.get(this);
final Account[] accounts = accountManager.getAccounts();
final int accountsCount = accounts.length;
Account account = null;
for(int i=0;i<accountsCount;i++) {
account = accounts[i];
AccountManagerFuture<Bundle> accountManagerFuture = null;
Bundle authTokenBundle = null;
try {
accountManagerFuture = accountManager.getAuthToken(account,
account.type, null, this, null, null);
authTokenBundle = accountManagerFuture.getResult(); //
exception
thrown here
Log.d("AUTH",
"accountName="+authTokenBundle.getString
(AccountManager.KEY_ACCOUNT_NAME)+
", accountType="+authTokenBundle.getString
(AccountManager.KEY_ACCOUNT_TYPE)+
", authTokenLabel="+authTokenBundle.getString
(AccountManager.KEY_AUTH_TOKEN_LABEL)+
", authToken="+authTokenBundle.getString
(AccountManager.KEY_AUTHTOKEN)
);
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
}
}
For the first account in the list (which happens to be my corporate
Exchange account), you get this exception:
11-13 13:21:50.778: WARN/System.err(5092):
java.lang.IllegalArgumentException: unknown authTokenType
11-13 13:21:50.786: WARN/System.err(5092): at
android.accounts.AccountManager.convertErrorToException
(AccountManager.java:656)
11-13 13:21:50.794: WARN/System.err(5092): at
android.accounts.AccountManager.access$500(AccountManager.java:53)
11-13 13:21:50.802: WARN/System.err(5092): at
android.accounts.AccountManager$AmsTask$Response.onError
(AccountManager.java:507)
11-13 13:21:50.802: WARN/System.err(5092): at
android.accounts.IAccountManagerResponse$Stub.onTransact
(IAccountManagerResponse.java:69)
11-13 13:21:50.810: WARN/System.err(5092): at
android.os.Binder.execTransact(Binder.java:287)
11-13 13:21:50.818: WARN/System.err(5092): at
dalvik.system.NativeStart.run(Native Method)
For the 2nd account in the list (which happens to be my Facebook
acocunt), the Droid consistently crashes and reboots itself :)
11-13 13:21:53.771: ERROR/AndroidRuntime(4682): Uncaught handler:
thread android.server.ServerThread exiting due to uncaught exception
11-13 13:21:53.771: ERROR/AndroidRuntime(4682): *** EXCEPTION IN
SYSTEM PROCESS. System will crash.
11-13 13:21:53.778: ERROR/AndroidRuntime(4682):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{android/android.accounts.GrantCredentialsPermissionActivity}:
java.lang.NullPointerException
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2454)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2470)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.os.Handler.dispatchMessage(Handler.java:99)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.os.Looper.loop(Looper.java:123)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
com.android.server.ServerThread.run(SystemServer.java:428)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): Caused by:
java.lang.NullPointerException
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.accounts.GrantCredentialsPermissionActivity.onCreate
(GrantCredentialsPermissionActivity.java:62)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2417)
11-13 13:21:53.778: ERROR/AndroidRuntime(4682): ... 6 more
Just thinking this through, I'm wondering if I'm misunderstanding the
purpose of the AccountManager, ie, should I even be able to use the
default Facebook account credentials in my app? If you've played w/
the Facebook REST API, you're required to sign every request you make
to Facebook using your unique developer API key and a session "secret"
that gets generated when the user authenticates your app (ie, user can
elect to grant your app the ability to read wall posts, post to your
wall, etc., and later revoke those rights). So lets say the user
grants full permission to the default Facebook app (and Account), then
I use that Account for my app; the user doesn't even know that my app
is accessing their Facebook profile, but I get full access via their
existing Account. Also, all the API requests coming from my app will
look like they're coming from the default Facebook app since they're
signed w/the default Facebook app's API key (via the authToken).
I'm thinking now that AccountManager is just a standardized mechanism
to store account information, but NOT to share that authentication
information across apps. So if my app offers Facebook integration,
and I create an Authenticator for it, the user would end up seeing 2
Facebook account types in the account manager screen (Droid default
and my custom one). If you write another app that accesses Facebook,
the user would see a third Facebook account type, etc.
A working example from the Android team would be nice :)
On Nov 11, 4:27 pm, Micah <[email protected]> wrote:
> To reply to your more specific questions, it is my understanding that
> the type you see in your log output is the type you would pass in to
> most of the AccountManager functions. The type should be a java style
> universally unique name (ie: domain.subdomain.accounttype) in the form
> of a string. So if you wanted to get a Google Auth Token you would
> call getAuthToken and pass in "com.google", for facebook you would
> pass in "com.facebook.auth.login".
>
> I am working on building my own account authenticator now and it's
> quite a bit more work than actually getting the auth token. Basically
> anywhere on your Droid that you see Google, Facebook and Exchange you
> could add your own account type, as well as allow applications by
> other developers to authenticate with your service.
>
> Here is the flow as I understand it, along with links to documentation
> for each part:http://docs.google.com/View?id=dhhtdbc7_4hhh4whg8
>
> Basically once you have an authenticator written and installed on the
> user's phone then the user would first need to create an account with
> the authenticator.
>
> One authenticator may track credentials for multiple users. ex: I may
> sign-in to the phone with two Google Accounts, then any app that needs
> an auth token for "com.google" would need to prompt the user with both
> accounts and ask them which one they would like to use.
>
> Once there is one or more accounts setup with the authenticator you
> would then ask the authenticator for an auth token for the desired
> account. The authenticator then may (or may not) prompt the user for
> additional credentials or it may pass an intent back to the calling
> application (depending on which version of getAuthToken you call) and
> leave it up to the calling application to send off the credential
> request intent (ex: if you are authenticating in the background it may
> be better to wait for the user to switch back to your app before
> prompting them, or pop-up a notification).
>
> Once authentication is complete the calling application will get a
> callback letting it know the results (auth token or failure). The
> calling application can then use that auth token to access services
> provided by "com.google" (or whoever you authenticated with), likely
> over an SSL connection, so the auth token isn't stolen.
>
> On Nov 9, 5:00 pm, Nerdrow <[email protected]> wrote:
>
>
>
> > I just tried this real quick on my Droid:
>
> > AccountManager mgr = AccountManager.get(this);
> > Account[] accts = mgr.getAccounts();
> > final int count = accts.length;
> > Account acct = null;
>
> > for(int i=0;i<count;i++) {
> > acct = accts[i];
> > Log.d("ACCT", "eclair account - name="+acct.name+",
> > type="+acct.type);
>
> > }
>
> > These are the results (masked :))
>
> > 11-09 16:13:09.143: DEBUG/ACCT(2495): eclair account -
> > name=<myemail>@gmail.com, type=com.google
> > 11-09 16:13:09.143: DEBUG/ACCT(2495): eclair account -
> > name=<myfacebook>@<facebook_email>.com, type=com.facebook.auth.login
> > 11-09 16:13:09.143: DEBUG/ACCT(2495): eclair account -
> > name=<myworkmail>@<mycompany>.com, type=com.android.exchange
>
> > Do you understand how to actually use the returned Account objects?
> > It looks like you have to use an AccountManager instance and call the
> > getAuthToken method, but this keeps failing for me since I don't know
> > the authTokenType to pass as an input parameter. The Account object
> > itself has no other useful fields as far as I can tell.
>
> > Related is the AbstractAccountAuthenticator, where you're supposed to
> > be able to add authenticator types to appear on the phone (by default
> > on the Droid you get 3, Google, Facebook, and Exchange). Judging by
> > the documentation this would allow you to integrate your app into the
> > "quick contact bar" or whatever it's called, as well as use the
> > ContactsContract api to facilitate contact syncing, but there's no
> > examples around any of this stuff, just the documentation. I found
> > this thread about the ContactsContract, but it doesn't help if I can't
> > add my authenticator
> > first:http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > Anyone have any ideas?
>
> > On Nov 8, 9:21 pm, Micah <[email protected]> wrote:
>
> > > In Android 2.0 there is a new android.accounts.AccountManagerclass
> > > has a function getAccounts()
> > > see:http://developer.android.com/reference/android/accounts/AccountManage...()
>
> > > Unfortunately, as most of you know the SDK doesn't come with any of
> > > the Google Apps that utilize the Google Account associated with the
> > > phone (Gmail, Google Talk, Calendar, etc.). This means that when you
> > > call getAccounts in an emulator it returns an empty array.
>
> > > The *hope* is that Google has modified the Google apps shipped with
> > > Android 2.0 to use theAccountManagerAPI instead of whatever internal
> > > and super-secret-closed system they were using before. If this is the
> > > case, then 3rd party apps can hopefully gain access to a Google Auth
> > > token via theAccountManagerinstead of having to ask the user for
> > > their username / password.
>
> > > Unfortunately, the only phone that has android 2.0 on it to my
> > > knowledge is the Motorola Droid. So this is a call out to any
> > > developers that have access to that phone to please
> > > callAccountManager.getAccounts and let us know whether or not there is a
> > > Google Account on a production android device.
>
> > > If not then it appears that it will be up to 3rd party developers to
> > > write an Authenticator (ideally a free / open sourced one) that
> > > returns a Google Auth token (and prompts / stores user's Google
> > > credentials with the android.accounts API.
--
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