0

I use the following code to download images. All images can be successfully downloaded except one. This image http://www.dailydealster.com/system/illustrations/18089/original/18089s.jpg could not be downloaded. Any one experience such a problem. While debugging the image is downloaded. But at release mode, this image is not downloading

try {
  ImageView i = (ImageView)findViewById(R.id.image);
  Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
  i.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}
indira
  • 6,569
  • 18
  • 65
  • 80

3 Answers3

0

My guess is that your image is too large to download it that way. Try downloading a smaller image and if it works, go and check out this post or this one.

Community
  • 1
  • 1
ikso
  • 61
  • 2
  • 9
0

This has worked for me in the past.

i = Drawable.createFromStream(((InputStream) new URL(imageUrl).getContent()),"image_name.png")
Raunak
  • 6,427
  • 9
  • 40
  • 52
0

I would be tempted to space out your retrieval code to something like this:

    URL url = new URL(photoUrl);
    URLConnection ucon = url.openConnection();
    Bitmap bitmap = BitmapFactory.decodeStream(ucon.getInputStream());

    ImageView image = (ImageView) findViewById(R.id.image);
    image.setImageBitmap(bitmap);

This way you avoid using casting, making it a more robust approach and could potentially solve your problem.

Hakan Ozbay
  • 4,639
  • 2
  • 22
  • 28