I am following Nick example on getting an authorization token from a google account. I get stuck when calling AccountManagerFuture getResult . I'm working on my device (HTC desire) and with a local google app engine started from Eclipse. If I get connected onto the Internet with my cellphone I am able to get an authentication token. But I would like to do it locally off line. Do you know if I should get hooked up to the Internet to make it work? If not, it's not clear what the getResult method does. Does it retrieve the token from a google server somewhere? Thanks.
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
AccountManager accountManager = AccountManager.get(getApplicationContext());
Account account = (Account)intent.getExtras().get("account");
accountManager.getAuthToken(account, "ah", false, new GetAuthTokenCallback(), null);
}
private class GetAuthTokenCallback implements AccountManagerCallback<Bundle> {
public void run(AccountManagerFuture<Bundle> result) {
Bundle bundle;
try {
System.out.println("result.isCancelled"+result.isCancelled());
// this prints false
System.out.println("result.isDone"+result.isDone());
//this prints true
bundle = result.getResult();
// when getResult is called I get an IOException without further details
Intent intent = (Intent)bundle.get(AccountManager.KEY_INTENT);
if(intent != null) {
startActivity(intent);
} else {
onGetAuthToken(bundle);
}
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
03-19 13:58:03.933: W/System.err(1801): java.io.IOException 03-19 13:58:03.933: W/System.err(1801): at android.accounts.AccountManager.convertErrorToException(AccountManager.java:1419) 03-19 13:58:03.933: W/System.err(1801): at android.accounts.AccountManager.access$400(AccountManager.java:134) 03-19 13:58:03.933: W/System.err(1801): at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1280) 03-19 13:58:03.933: W/System.err(1801): at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69) 03-19 13:58:03.933: W/System.err(1801): at android.os.Binder.execTransact(Binder.java:288) 03-19 13:58:03.933: W/System.err(1801): at dalvik.system.NativeStart.run(Native Method)