您好我正在使用该Picasso库从URL下载图像.
网址:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/s200x200/1472865_191408954385576_14109897_n.jpg
URL使用的是https协议,在这里我无法下载使用https协议的映像Picasso.
它不支持下载使用https协议的图像,只有当我使用http proctocol时它才对我有用吗?
在这里,我试图获取使用https协议的位图
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);
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?
小智 35
在您的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'
Run Code Online (Sandbox Code Playgroud)
而这个类而不是原始Picasso类
毕加索课程:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
用法示例:
PicassoTrustAll.getInstance(context)
.load(url)
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11049 次 |
| 最近记录: |