I have an image URL. I want to display an image from this URL in an ImageView but I am unable to do that.
How can this be achieved?
Here is sample code for display Image from URL.
public static Void downloadfile(String fileurl, ImageView img) {
Bitmap bmImg = null;
URL myfileurl = null;
try {
myfileurl = new URL(fileurl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myfileurl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
if (length > 0) {
int[] bitmapData = new int[length];
byte[] bitmapData2 = new byte[length];
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
img.setImageBitmap(bmImg);
}
} catch (IOException e) {
e.printStackTrace();
}
}