2012-03-19 85 views
2

我正在关注从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)

回答

2

我有这个问题,是由于我的wifi连接死亡的事实造成的。确保你已连接到互联网。

0

您可能正在使用不支持google api的图片。 请确保使用安装了Google API的Android SDK管理器,然后再检查您的Android虚拟设备,看看您是否使用google API作为目标

相关问题