我在需要獲取圖像授權來源的應用程序中使用通用圖像加載程序。在通用圖像加載程序中訪問受保護的圖像
到目前爲止,我已經擴展了我自己的類的URLConnectionImageDownloader類,並重寫我自己implemetation方法getStreamFromNetwork,設置授權頭中的URLConnection對象爲這樣:
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));
}
,並設立我ImageLoader的...
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(MainActivity.this)
.imageDownloader(new authURLConnectionImageDownloader())
.build();
imageLoader.init(config);
到目前爲止,我有無法得到它的工作。該圖像未被下載。但更重要的是,我在getStreamFromNetwork()中放置了一個斷點,它從來沒有被打過?我究竟做錯了什麼?
感謝解決方案! :) – Sadegh