[英]This image could not be downloaded in android. Why?
我使用以下代码下载图像。 除一张外,所有图像均可成功下载。 无法下载该图片http://www.dailydealster.com/system/illustrations/18089/original/18089s.jpg 。 任何人都会遇到这样的问题。 在调试时,将下载映像。 但是在发布模式下,此图像未下载
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();
}
过去这对我有用。
i = Drawable.createFromStream(((InputStream) new URL(imageUrl).getContent()),"image_name.png")
我很想将您的检索代码间隔成这样:
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);
这样,您可以避免使用强制转换,使其成为更可靠的方法,并有可能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.