如何配置 Universal Image Loader 以显示来自 https 的图像?
How can I configure Universal Image Loader to display images from https?
当我与服务器的连接是 https 时,通用图像加载器出现问题。我可以使用 http 显示图像,但不能使用 https 连接。如何在 UIL 中设置 sslSocketFactory?我的 UIL 代码如下所示;
Map<String,String> authHeaders = new HashMap<>();
authHeaders.put("token", LocalStorage.getUserToken(ctx));
DisplayImageOptions defaults = new DisplayImageOptions.Builder()
.displayer(new FadeInBitmapDisplayer(300, true, true, false))
.showImageOnFail(R.drawable.ic_image_fail)
.showImageForEmptyUri(R.drawable.ic_image_fail)
.cacheOnDisk(true)
.cacheInMemory(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.extraForDownloader(authHeaders)
.build();
ImageLoaderConfiguration.Builder configsBuilder = new ImageLoaderConfiguration.Builder(ctx)
.imageDownloader(new AuthImageDownloader(ctx))
.defaultDisplayImageOptions(defaults);
ImageLoader.getInstance().init(configsBuilder.build());
开球样本:
public class SslRuinedDownloader extends BaseImageDownloader {
public SslRuinedDownloader(Context context) {
super(context);
}
@Override
protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
HttpsURLConnection conn = super.createConnection(url, extra);
//here you go
conn.setSSLSocketFactory(...);
return conn;
}
}
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.imageDownloader(new SslRuinedDownloader(getApplicationContext()))
.build();
当我与服务器的连接是 https 时,通用图像加载器出现问题。我可以使用 http 显示图像,但不能使用 https 连接。如何在 UIL 中设置 sslSocketFactory?我的 UIL 代码如下所示;
Map<String,String> authHeaders = new HashMap<>();
authHeaders.put("token", LocalStorage.getUserToken(ctx));
DisplayImageOptions defaults = new DisplayImageOptions.Builder()
.displayer(new FadeInBitmapDisplayer(300, true, true, false))
.showImageOnFail(R.drawable.ic_image_fail)
.showImageForEmptyUri(R.drawable.ic_image_fail)
.cacheOnDisk(true)
.cacheInMemory(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.extraForDownloader(authHeaders)
.build();
ImageLoaderConfiguration.Builder configsBuilder = new ImageLoaderConfiguration.Builder(ctx)
.imageDownloader(new AuthImageDownloader(ctx))
.defaultDisplayImageOptions(defaults);
ImageLoader.getInstance().init(configsBuilder.build());
开球样本:
public class SslRuinedDownloader extends BaseImageDownloader {
public SslRuinedDownloader(Context context) {
super(context);
}
@Override
protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
HttpsURLConnection conn = super.createConnection(url, extra);
//here you go
conn.setSSLSocketFactory(...);
return conn;
}
}
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.imageDownloader(new SslRuinedDownloader(getApplicationContext()))
.build();