Answer the question
In order to leave comments, you need to log in
Open(show) Image from URL?
you need to open an image from the Internet by URl and display it in an ImageView.
Tried many options
1. Here is one example
String stringURL = "http://icons.iconarchive.com/icons/icons8/ios7/72/Messaging-Lol-icon.png";
InputStream is = null;
BufferedInputStream bis = null;
Bitmap bmp = null;
try {
URL url = new URL(stringURL);
URLConnection conn = url.openConnection();
conn.connect();
is = conn.getInputStream();
bis = new BufferedInputStream(is);
bmp = BitmapFactory.decodeStream(bis);
}catch (Exception ignored) {
} finally {
try {
if( is != null )
is.close();
if( bis != null )
bis.close();
} catch (IOException e) {
}
}
imageView.setImageBitmap(bmp);
try {
URL url = new URL("http://icons.iconarchive.com/icons/icons8/ios7/72/Messaging-Lol-icon.png");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
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);
}
}
new DownloadImageTask(imageView)
.execute(stringURL);
Answer the question
In order to leave comments, you need to log in
Guys, this is just tin. I started to feel like a moron. It seems that with the codes (I tried Not 1) everything is fine and *** did not do them, gave UnknownHostException. Everything was written in the manifesto.
Stupid mistake, I thought that everything was fine with the manifest,
that's how it was
that's how it was and everything works
Spent a day through such a stupid mistake
. Thank you for trying to help. I already got you
You've gone the wrong way, with Picasso you don't need any tasks. Read the documentation carefully.
What writes in the error if it is not ignored here } catch (Exception ignored) {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question