Passing header to Picasso while viewing the image using url - Android

泪湿孤枕 提交于 2019-12-06 06:22:08

问题


I need to pass a header when I try to show a image using Picasso.

Can any one suggest how to add header to picasso while viewing the image.


回答1:


You can use downloader for that:

https://github.com/JakeWharton/picasso2-okhttp3-downloader

Example:

OkHttpClient client = new OkHttpClient.Builder()
        .addInterceptor(new Interceptor() {
            @Override
            public Response intercept(Chain chain) throws IOException {
                Request newRequest = chain.request().newBuilder()
                        .addHeader("custom-header", "custom-header-value")
                        .build();
                return chain.proceed(newRequest);
            }
        })
        .build();

Picasso picasso = new Picasso.Builder(context)
        .downloader(new OkHttp3Downloader(client))
        .build();

Keep in mind that if you are using OkHttpClient already, you should use that instance or create new one using client.newBuilder(). This way, both instances will be using the same request queue.



来源:https://stackoverflow.com/questions/49673110/passing-header-to-picasso-while-viewing-the-image-using-url-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!