![](/img/trans.png)
[英]AccountManager returns invalid auth_token when run on android 2.3
[英]How to store and retrieve auth_token to/from AccountManager
我正在使用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();
}
有什么建議么 ?
最后,我可以通過以下代碼段檢索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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.