问题
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)
回答1:
I had this problem, and it was caused by the fact that my wifi connection died. Make sure you are connected to the internet.
回答2:
It's possible that you are using an image that doesn't support google api. Make sure using the Android SDK manager that you have the google API installed and then also check you Android Virtual device to see that you are using the google API as target
来源:https://stackoverflow.com/questions/9768650/android-accountmanagerfuture-getresult-gives-ioexcelption-when-trying-to-get-aut