我正在尝试缓存数据以供离线使用而没有成功。以下是我目前的工作。
//fetch news details
private void FetchHeadline(){
showDialog();
btnRefresh.setVisibility(View.GONE);
// We first check for cached request
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Entry entry = cache.get(NEWS_URL);
if (entry != null) {
Log.e("", "babaaaaaaaaaaaaaaaaaaaaaaaa");
// fetch the data from cache
try {
String data = new String(entry.data, "UTF-8");
try {
parseJsonFeed(new JSONArray(data));
} catch (JSONException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
// making fresh volley request and getting json
JsonArrayRequest jsonReq = new JsonArrayRequest(
NEWS_URL + dbHelper.getAuth().getString(0), new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.e(TAG, "Response: " + response.toString());
if (response != null) {
parseJsonFeed(response);
}
hideDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
btnRefresh.setVisibility(View.VISIBLE);
hideDialog();
Log.e(TAG, "Response: " + error.getMessage());
try {
if (error.getMessage().equalsIgnoreCase("java.io.IOException: No authentication challenges found")){
moveToLoginActivity();}
}catch(Exception e){}
}
});
// Adding request to volley request queue
AppController.getInstance().addToRequestQueue(jsonReq);
}
我将以下内容添加到我的.htaccess
但没有成功
<IfModule headers_module>
# 1 Month for most static assets
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=36000, public"
</filesMatch>
</IfModule>