I am using the universal image loader in an app that needs to fetch images an authorized source.
So far, I have extended the URLConnectionImageDownloader class with my own class, and overridden the method getStreamFromNetwork with my own implemetation that sets the authorization header in the URLConnection object as such:
public class authURLConnectionImageDownloader extends URLConnectionImageDownloader {
@Override
public InputStream getStreamFromNetwork(URI imageUri) throws IOException {
String auth = Base64.encodeToString(("username" + ":"+"psswd").getBytes(), Base64.NO_WRAP);
URLConnection conn = imageUri.toURL().openConnection();
conn.setRequestProperty("Authorization", "Basic " + auth);
conn.setConnectTimeout(DEFAULT_HTTP_CONNECT_TIMEOUT);
conn.setReadTimeout(DEFAULT_HTTP_READ_TIMEOUT);
return new FlushedInputStream(new BufferedInputStream(conn.getInputStream(), BUFFER_SIZE));
}
and for setting up my ImageLoader...
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(MainActivity.this)
.imageDownloader(new authURLConnectionImageDownloader())
.build();
imageLoader.init(config);
So far I have unable to get it to work. The image is not downloaded. But more importantly I have put a breakpoint in getStreamFromNetwork() and it is never hit? What am I doing wrong?