您好我正在使用Picasso库从URL下载图像.
URL使用https协议,在这里我无法使用Picasso下载https协议的图像.
它不支持下载使用https协议的图像,只有当我使用http proctocol时它才对我有用吗?
com.squareup.picasso.Target target = new com.squareup.picasso.Target() {
@Override
public 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);
}
});
}
@Override
public 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();
}
@Override
public 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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。