1

我使用如下所示的代码从 AccountManager 获取身份验证令牌,它在我的三星 Galaxy Tab 10.1、联想 Ideapad 和摩托罗拉 RARZ 手机上完美运行,但在我的 Galaxy S3 上因 IOException 而失败。

环顾四周,这似乎是由于缺乏网络(例如没有 wifi/3G)造成的,但手机可以上网,我可以浏览互联网和接收电子邮件。

有关此问题的原因和解决方法的任何提示?由于 Galaxy S3 是最受欢迎的 Android 手机之一,我不能忽略它。

public class LoginActivity extends SherlockActivity implements OnItemClickListener,
                                                 AccountManagerCallback<Bundle>
{
  public final static String GOOGLE_SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.login";

  private String mToken;

  private void requestToken() {
    mAccountManager.getAuthToken(mAccount, GOOGLE_SCOPE, null, this, this, null);
  }

  @Override
  public void run(AccountManagerFuture<Bundle> result) {
    Bundle bundle = null;

    try {
      bundle  = result.getResult();
      final Intent loginIntent = (Intent)bundle.get(AccountManager.KEY_INTENT);
      if(loginIntent != null) {
        startActivityForResult(loginIntent, AUTH_REQ_CODE);
      } else {
        mToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
      }
    } catch ( final IOException e ) {
      Log.e(TAG, e.toString());
      e.printStackTrace();
    } catch ( final AuthenticatorException ae ) {
      Log.e(TAG, ae.toString());
      ae.printStackTrace();
    } catch ( final OperationCanceledException oce ) {
      Log.e(TAG, oce.toString());
      oce.printStackTrace();
    } catch ( final Exception ex ) {
      Log.e(TAG, ex.toString());
      ex.printStackTrace();
    }
  }
}

}

4

0 回答 0