【问题标题】:How to store and retrieve auth_token to/from AccountManager如何在 AccountManager 中存储和检索 auth_token
【发布时间】:2013-12-12 16:59:21
【问题描述】:

我正在使用AccountManager 来存储 auth_token。我正在使用以下代码来存储 auth_token。但我无法找回它。

AccountManager.get(this).addAccountExplicitly(account, "", bundle);

而且,我正在使用以下代码(使用 Volley 库)将其取回,但它会抛出 AuthFailureError。

try {
    Logging.d(LOG_TAG, "AUTH TOKEN : "
            + (new AndroidAuthenticator(this, account,
                    CustomAuthenticator.AUTHTOKEN_TYPE).getAuthToken()));
} catch (AuthFailureError e) {
    Logging.d(LOG_TAG, "AUTH FAILURE");
    e.printStackTrace();
}

有什么建议吗?

【问题讨论】:

    标签: android authentication accountmanager


    【解决方案1】:

    最后,我可以通过这个 sn-p 检索 auth_token:

    final AccountManagerFuture<Bundle> future = AccountManager.get(this)
            .getAuthToken(account, authTokenType, null, this, null, null);
    
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Bundle bnd = future.getResult();
                final String authtoken = bnd
                        .getString(AccountManager.KEY_AUTHTOKEN);
                Logging.d(LOG_TAG, (authtoken != null) ? "SUCCESS!\ntoken: "
                        + authtoken : "FAIL");
            } catch (Exception e) {
                e.printStackTrace();                }
        }
    }).start();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-31
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-22
      相关资源
      最近更新 更多