壁画:如何添加RequestProperty到ImageRequestBuilder? [英] Fresco: How to add RequestProperty to the ImageRequestBuilder?

查看:188
本文介绍了壁画:如何添加RequestProperty到ImageRequestBuilder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片管道采用与Android捆绑在一起的 HttpURLConnection类网​​络库。

The image pipeline uses the HttpURLConnection networking library bundled with Android.

HttpURLConnection connection.setRequestProperty("Charset", "utf-8");

壁画:怎样RequestProperty添加到ImageRequestBuilder

Fresco: How to add RequestProperty to the ImageRequestBuilder?

推荐答案

如果你正在谈论请求头,下面是我在我的应用程序已经做了

If you are talking about request headers, Here is what I have done in my app

DiskCacheConfig mainDiskCacheConfig = DiskCacheConfig.newBuilder()
            .setBaseDirectoryPath(sContext.getCacheDir())
            .setBaseDirectoryName("cache")
            .setMaxCacheSize(1024 * 1024 * 1024) // max cache size
            .setMaxCacheSizeOnLowDiskSpace(50 * 1024 * 1024) // for low disk cache
            .setMaxCacheSizeOnVeryLowDiskSpace(10 * 1024 * 1024) // for
            .build();

    OkHttpClient client = new OkHttpClient();

    client.interceptors().add(new Interceptor() {
        @Override
        public Response intercept(Interceptor.Chain chain) throws IOException {
            com.squareup.okhttp.Request originalRequest = chain.request(); //Current Request
            com.squareup.okhttp.Request requestWithToken = null; //The request with the access token which we will use if we have one instead of the original
            requestWithToken = originalRequest.newBuilder()
                    .addHeader(Constant.AUTH_HEADER, BackgroundService.getAuthenticationHeader())
                    .addHeader(Constant.X_USER_ID, Wrapper.getInstance().getUserId())
                    .addHeader(Constant.X_DEVICE_KEY, DeviceUtils.getDeviceDetails(App.this).getAndroid_id())
                    .addHeader(Constant.X_ACCEPT_LANGUAGE, Constant.ACCEPT_LANGUAGE_ENGLISH)
                    .build();
            Response response = chain.proceed((requestWithToken != null ? requestWithToken : originalRequest)); //proceed with the request and get the response
            if (response != null && response.code() != HttpURLConnection.HTTP_OK) {
                response.body().close();
            }
            return response;
        }
    });

    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, client)
            .setMainDiskCacheConfig(mainDiskCacheConfig)
            .build();
    Fresco.initialize(this, config);

这篇关于壁画:如何添加RequestProperty到ImageRequestBuilder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆