Menu Home

Android install HTTP Cache

// > Android 4.0, 向下兼容

private void enableHttpResponseCache() {
    try {
        long cacheSize = 10 * 1024 * 1024;
        File cacheDir = new File(getCacheDir(), "cache");
        Class.forName("android.net.http.HttpResponseCache")
            .getMethod("install", File.class, long.class)
            .invoke(null, httpCacheDir, httpCacheSize);
    } catch (Exception httpResponseCacheNotAvailable) {
    }
}

Categories: android应用 网络

Tagged as:

lnmcc

Leave a Reply

Your email address will not be published.