android – 使用Picasso的Custom Downloader

我必须从URL下载图像,该URL需要一些标题(用户名,密码)以及请求.所以我使用 here给出的代码.但调用函数会产生错误
java.lang.NoClassDefFoundError: com.squareup.okhttp.OkHttpClient
at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:72)

我正在使用Picasso 2.3.3和okhttp-urlconnection-2.0.0-RC2库
该问题已在this发布,但改为2.3.2无效.

解决方法

你的项目中是否包含OkHttp?如果没有,问题是你正在使用OkHttpDownloader.您可以在项目中包含OkHttp库,也可以在下面添加UrlConnectionDownloader.

这是我最终得到的结果.

public static Picasso getimageLoader(Context ctx) {
    Picasso.Builder builder = new Picasso.Builder(ctx);

    builder.downloader(new UrlConnectionDownloader(ctx) {
        @Override
        protected HttpURLConnection openConnection(Uri uri) throws IOException {
            HttpURLConnection connection = super.openConnection(uri);
            connection.setRequestProperty("X-HEADER","VAL");
            return connection;
        }
    });

    return builder.build();
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...