本文整理汇总了Java中android.net.http.HttpResponseCache.install方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseCache.install方法的具体用法?Java HttpResponseCache.install怎么用?Java HttpResponseCache.install使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.http.HttpResponseCache
的用法示例。
在下文中一共展示了HttpResponseCache.install方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_pane);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_toolbar);
setSupportActionBar(toolbar);
if (savedInstanceState == null) {
FragmentManager.enableDebugLogging(true);
getSupportFragmentManager().beginTransaction()
.add(R.id.container, SampleListFragment.newInstance(), SampleListFragment.TAG)
.commit();
}
// http response cache
File httpCacheDir = new File(getCacheDir(), "http");
long httpCacheSize = 100 * 1024 * 1024; // 100 MiB
try {
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
Log.i(SampleListActivity.class.getSimpleName(), "HTTP response cache installation failed:" + e);
}
}
示例2: onCreate
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// cookie store
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
// init cache for http responses
try {
File httpCacheDir = new File(getApplicationContext().getCacheDir(), "http");
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch(IOException e){
Log.i(TAG, "HTTP response cache installation failed:" + e);
}
}
示例3: getRestBuilder
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
public static RestAdapter.Builder getRestBuilder(final Context context, final String url) {
if (!sResponseCache) {
try {
final File httpCacheDir = new File(context.getCacheDir(), "http");
final long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
e.printStackTrace();
}
sResponseCache = true;
}
return new RestAdapter.Builder()
.setEndpoint(url)
.setConverter(JACKSON_CONVERTER)
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Authorization",
"Basic " + XDAConstants.ENCODED_AUTHORIZATION);
}
});
}
示例4: cacher
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
public void cacher()
{
httpCacheDir = getExternalCacheDir();
try {
HttpResponseCache.install(httpCacheDir, httpCacheSize); //Setting the cache
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: onCreate
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
HttpResponseCache.install(new File(getCacheDir(), "http"), 5 * 1024 * 1024);
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Could not register cache " + e.getMessage());
}
}
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
Thread.setDefaultUncaughtExceptionHandler(new YalpStoreUncaughtExceptionHandler(getApplicationContext()));
registerDownloadReceiver();
registerInstallReceiver();
}
示例6: enableHttpCaching
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
/**
* Enable caching for http request : must use HttpUrlConnection !
* see : <a href="http://developer.android.com/reference/android/net/http/HttpResponseCache.html">HttpResponseCache</a>
*
* @param context
*/
public static void enableHttpCaching(Context context) {
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
try {
File httpCacheDir = new File(context.getCacheDir(), "http");
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
Log.i("", "HTTP response cache failed:" + e);
}
}
示例7: onCreate
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
File httpCacheDir = new File(getCacheDir(), "http");
long httpCacheSize = 0;
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
Log.i(getClass().getName(), "HTTP response cache installation failed:" + e);
}
}
示例8: clear
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
public void clear() throws IOException {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.delete();
}
HttpResponseCache.install(file, size);
}
示例9: enableHttpResponseCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void enableHttpResponseCache() {
final long httpCacheSize = 10 * 1024 * 1024;
final File httpCacheDir = new File(getCacheDir(), "http");
try {
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
示例10: enableHttpResponseCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
/**
* Installs the HttpResponseCache
* Note this will only work on Android 4.0+
*/
private void enableHttpResponseCache() {
try {
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
File httpCacheDir = new File(getCacheDir(), "http");
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (Exception httpResponseCacheNotAvailable) {
Log.d(TAG, "HTTP response cache is unavailable.");
}
}
示例11: enableHttpResponseCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
private static void enableHttpResponseCache(Context context) {
try {
long httpCacheSize = 5 * 1024 * 1024; // 5MB
File httpCacheDir = new File(context.getCacheDir(), "http");
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
AppLog.w(T.UTILS, "Failed to enable http response cache");
}
}
示例12: installHttpResponseCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static HttpResponseCache installHttpResponseCache(final File cacheDir)
throws IOException {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache == null) {
final long maxSize = calculateDiskCacheSize(cacheDir);
cache = HttpResponseCache.install(cacheDir, maxSize);
}
return cache;
}
示例13: install
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
static Object install(Context context) throws IOException {
File cacheDir = Utils.createDefaultCacheDir(context);
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache == null) {
long maxSize = Utils.calculateDiskCacheSize(cacheDir);
cache = HttpResponseCache.install(cacheDir, maxSize);
}
return cache;
}
示例14: installedCacheIsReturned
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Test
public void installedCacheIsReturned() throws Exception {
assertThat(HttpResponseCache.getInstalled()).isNull();
HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
HttpResponseCache installed = HttpResponseCache.getInstalled();
assertThat(installed).isSameAs(cache);
assertThat(installed.maxSize()).isEqualTo(42);
}
示例15: countsStartAtZero
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Test
public void countsStartAtZero() throws Exception {
HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
assertThat(cache.getHitCount()).isZero();
assertThat(cache.getNetworkCount()).isZero();
assertThat(cache.getRequestCount()).isZero();
}