Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an ImageView by URL in Android? [closed]

How do you use an image referenced by URL in an ImageView?

like image 285
Praveen Avatar asked Mar 18 '10 17:03

Praveen


People also ask

Which library is used to load an image from URL into an ImageView?

UrlImageViewHelper will fill an ImageView with an image that is found at a URL.

How do I create a URL for an image?

Set the bitmap to your ImageView. imageView. setImageBitmap(getBitmapFromURL(url));


1 Answers

From Android developer:

// show The Image in a ImageView new DownloadImageTask((ImageView) findViewById(R.id.imageView1))             .execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");  public void onClick(View v) {     startActivity(new Intent(this, IndexActivity.class));     finish();  }  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);     } } 

Make sure you have the following permissions set in your AndroidManifest.xml to access the internet.

<uses-permission android:name="android.permission.INTERNET" /> 
like image 50
Android Developer Avatar answered Sep 28 '22 03:09

Android Developer