我已經找到了如何設置一個基本認證頭到ImageLoader的。我誤解了該鏈接的答案same topic。因此,信用轉到真正的回答者。 反正的訣竅是一個HurlStack添加到getRequestQueue方法如下:
public RequestQueue getRequestQueue()
{
if (mRequestQueue == null) {
HurlStack stack = new HurlStack() {
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> headers)
throws IOException, AuthFailureError {
String auth = "Basic " + Base64.encodeToString((GlobalVariables.getInstance().getWS_KEY()+":").getBytes(),
Base64.NO_WRAP);
headers.put("Authorization", auth);
return super.performRequest(request, headers);
}
};
mRequestQueue = Volley.newRequestQueue(getApplicationContext(),stack);
}
return mRequestQueue;
}
的請求隊列對象被放置到全局類,並施加一個單模式,因此這意味着無論何時請求RequestQueue,授權標題將在其中。希望能幫助到你 !
對不起,我不明白'哪些不可能付諸實踐。此外,發佈你的代碼和你的logcat的更多信息 – BNK