我正在關注從Google帳戶獲取授權令牌的Nick example。 我在調用AccountManagerFuture getResult時遇到困難。我正在使用我的設備(HTC願望)以及從Eclipse開始的本地Google應用引擎。如果我通過手機連接到互聯網,我可以獲得身份驗證令牌。但我想在本地脫機。你知道我是否應該連接互聯網以使其工作? 如果不是,則不清楚getResult方法的作用。它是否從某個地方的谷歌服務器檢索到令牌? 謝謝。Android AccountManagerFuture getResult在嘗試獲取授權令牌時給出IOEXcelption
@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):在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.execTra nsact(Binder.java:288) 03-19 13:58:03.933:W/System.err(1801):at dalvik.system.NativeStart.run(Native Method)