Answer the question
In order to leave comments, you need to log in
How to get cache using HttpUrlConnection?
Happy New Year to all!!!
In the Application class I do the following:
try {
File httpCacheDir = new File(getCacheDir(), "http");
long httpCacheSize = 30 * 1024 * 1024; // 30 MiB
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
if(BuildConfig.DEBUG)
Log.v("my app", "HTTP response cache installation failed:" + e);
}
URL url = new URL("some url addess");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setUseCaches(true);
urlConnection.setDoInput(true);
urlConnection.addRequestProperty("Cache-Control", "max-state=2419200");
InputStream inputStream = urlConnection.getInputStream();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question