Android Ocasionally Downloads Images From Url
A part of my application is to download images from a url and parse them to listview and single imgaview. Generaly it does not work, however some images appear occasionally. publi
Solution 1:
I think it might be problem in url means it contain blank space in it. so to download image if its url contain blank use below code.
publicvoidDisplayImage(String uurl, int loader, ImageView imageView)
{
String url = uurl.replaceAll(" ", "%20");
stub_id = loader;
imageViews.put(imageView, url);
Bitmap bitmap=memoryCache.get(url);
if(bitmap!=null)
imageView.setImageBitmap(bitmap);
else
{
queuePhoto(url, imageView);
imageView.setImageResource(loader);
}
}
Use this to download bitmap from specified url.
BitmapdownloadBitmap(String url)
{
URL url_1 = null;
try {
url_1 = newURL(url);
bmp = BitmapFactory.decodeStream(url_1.openConnection().getInputStream());
} catch (Exception e) {
Log.v("Error while downloading bitmap from url", e.getMessage());
}
return bmp;
}
Post a Comment for "Android Ocasionally Downloads Images From Url"