标签:
转载自: http://blog.csdn.net/kesenhoo/article/details/7395817
long currentTime = System.currentTimeMillis()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); long expires = conn.getHeaderFieldDate("Expires", currentTime); long lastModified = conn.getHeaderFieldDate("Last-Modified", currentTime); setDataExpirationDate(expires); if (lastModified < lastUpdateTime) { // Skip update } else { // Parse update }
Context.getExternalCacheDir();
Context.getCache();
private void enableHttpResponseCache() { try { long httpCacheSize = 10 * 1024 * 1024; // 10 MiB File httpCacheDir = new File(getCacheDir(), "http"); Class.forName("android.net.http.HttpResponseCache") .getMethod("install", File.class, long.class) .invoke(null, httpCacheDir, httpCacheSize); } catch (Exception httpResponseCacheNotAvailable) { Log.d(TAG, "HTTP response cache is unavailable."); } }
学习自:http://developer.android.com/training/efficient-downloads/redundant_redundant.html,谢谢!
[Android Traffic] 使用缓存来避免重复的下载
标签:
原文地址:http://www.cnblogs.com/0616--ataozhijia/p/4324447.html