If you just want to use native android code, you can download it using AsyncTask
and then set it in onPostExecute
.
Call it as:
//pass image view while creating AskyncTask object and pass url as parameter
new DownloadImageTask((ImageView) findViewById(R.id.yourImageView)).execute("your_url_here");
AsynTask to call:
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
I just saw that a similar answer is also mentioned in the url which you've mentioned in the question. This is working for my app. If its gives MalformedUrlException
, then you can try checking if url is proper and if needed encode it properly.