2

I need to load, and update image from URL.

Using AsyncTask, Iam able to load image from URL bt i need to reload image from url for every 10 secs.

Please help me how i can solve this issue.

Thanks in advance

praveenb
  • 10,549
  • 14
  • 61
  • 83

2 Answers2

3

@Praveenb try following ,

Bitmap bmImg;
void downloadFile(String fileUrl){
URL myFileUrl =null; 
try {
myFileUrl= new URL(fileUrl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();

InputStream is = conn.getInputStream();

bmImg = BitmapFactory.decodeStream(is); 
    // it will decode the input stream and will load the bitmat in bmImg variable

imView.setImageBitmap(bmImg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
sohilv
  • 1,712
  • 2
  • 16
  • 21
2

following code works fine for me,

class DownloadImage extends AsyncTask<Void, Void, Drawable>{
        @Override
        protected Drawable doInBackground(Void... params) {
            return Util.getImageFromURL(imageURL); 
        }

        @Override
        protected void onPostExecute( Drawable d ) {
            getImageIcon().setImageDrawable(d);
        }

}
new DownloadImage().execute();

and if you are showing image in list view you should follow this http://github.com/commonsguy/cwac-thumbnail

sohilv
  • 1,712
  • 2
  • 16
  • 21
  • Hi sohilvassa, I see that u are showing image from url in imageview. is this image will update continuously from the url?. Please let me know hw i can get this work. thanks for reply – praveenb Jul 09 '10 at 18:18