您好我正在使用Picasso库从URL下载图像.
网址:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/s200x200/1472865_191408954385576_14109897_n.jpg
URL使用https协议,在这里我无法使用Picasso下载https协议的图像.
它不支持下载使用https协议的图像,只有当我使用http proctocol时它才对我有用吗?
在这里,我试图获取使用https协议的位图
com.squareup.picasso.Target target = new com.squareup.picasso.Target() {@OverrIDepublic voID onBitmapLoaded(Bitmap bitmap, LoadedFrom loadedFrom) { userProfile.setBitmap(bitmap); // call the Web API to register the walker here new AudioStreetAsyncTask(getActivity(), userProfile, getString(R.string.registration_processing_message), new TaskCompleteListener() { @OverrIDe public voID onTaskCompleted(String JsonResponse) { Log.d(TAG, JsonResponse); } });}@OverrIDepublic voID onBitmapFailed(Drawable drawable) { userProfile.setBitmap(null); // call the Web API to register the walker here new AudioStreetAsyncTask(getActivity(), userProfile, getString(R.string.registration_processing_message), new TaskCompleteListener() { @OverrIDe public voID onTaskCompleted(String JsonResponse) { Log.d(TAG, JsonResponse); } }).execute();}@OverrIDepublic voID onPrepareLoad(Drawable drawable) {}};Picasso.with(getActivity()).load(imgurl.toString()).into(target);
任何想法 ?
解决方法:
在Gradle中使用这些依赖项:
compile 'com.squareup.okhttp:okhttp:2.2.0'compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'compile 'com.squareup.picasso:picasso:2.4.0'
而这个班级而不是原来的毕加索班级
毕加索课程:
public class PicassoTrustAll { private static Picasso mInstance = null; private PicassoTrustAll(Context context) { OkhttpClIEnt clIEnt = new OkhttpClIEnt(); clIEnt.setHostnameVerifIEr(new HostnameVerifIEr() { @OverrIDe public boolean verify(String s, SSLSession sslSession) { return true; } }); TrustManager[] trustAllCerts = new TrustManager[] { new x509trustmanager() { @OverrIDe public voID checkClIEntTrusted( java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } @OverrIDe public voID checkServerTrusted( java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } @OverrIDe public java.security.cert.X509Certificate[] getAcceptedissuers() { return new java.security.cert.X509Certificate[] {}; } } }; try { SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); clIEnt.setSslSocketFactory(sc.getSocketFactory()); } catch (Exception e) { e.printstacktrace(); } mInstance = new Picasso.Builder(context) .downloader(new OkhttpDownloader(clIEnt)) .Listener(new Picasso.Listener() { @OverrIDe public voID onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { Log.e("PICASSO", exception); } }).build(); } public static Picasso getInstance(Context context) { if (mInstance == null) { new PicassoTrustAll(context); } return mInstance; }}
用法示例:
PicassoTrustAll.getInstance(context) .load(url) .into(imageVIEw);
总结 以上是内存溢出为你收集整理的android – Picasso不支持下载使用https协议的图像全部内容,希望文章能够帮你解决android – Picasso不支持下载使用https协议的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)