当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponseCache.install方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:flurry,项目名称:StreamAds-Android,代码行数:26,代码来源:SampleListActivity.java

示例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);
    }
}
 
开发者ID:hanscappelle,项目名称:android-rest-example,代码行数:19,代码来源:MyApplication.java

示例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);
                }
            });
}
 
开发者ID:xda,项目名称:XDA-One,代码行数:24,代码来源:RetrofitClient.java

示例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();
    }
}
 
开发者ID:rishabh115,项目名称:Odyssey2017,代码行数:10,代码来源:FeedActivity.java

示例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();
}
 
开发者ID:yeriomin,项目名称:YalpStore,代码行数:16,代码来源:YalpStoreApplication.java

示例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);
    }
}
 
开发者ID:MobileTribe,项目名称:pandroid,代码行数:16,代码来源:NetworkUtils.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-High-Performance-Programming,代码行数:11,代码来源:ResponseCache.java

示例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);
}
 
开发者ID:witrisna,项目名称:android-restless,代码行数:9,代码来源:FileCache.java

示例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);
    }
}
 
开发者ID:crm416,项目名称:android-lite,代码行数:12,代码来源:MainActivity.java

示例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.");
    }
}
 
开发者ID:nico-gonzalez,项目名称:volley-it,代码行数:14,代码来源:MainActivity.java

示例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");
    }
}
 
开发者ID:ldsddn,项目名称:wordpress_app_android,代码行数:10,代码来源:WordPress.java

示例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;
}
 
开发者ID:satorufujiwara,项目名称:lighthttp,代码行数:11,代码来源:CacheUtil.java

示例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;
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:10,代码来源:UrlConnectionDownloader.java

示例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);
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:9,代码来源:HttpResponseCacheTest.java

示例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();
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:8,代码来源:HttpResponseCacheTest.java


注:本文中的android.net.http.HttpResponseCache.install方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。