views:

75

answers:

3

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

A: 

You mean upload image? Then take a look at that http://stackoverflow.com/questions/3038409/how-to-send-http-post-request-and-recieve-response/3038747#3038747.

Fedor
Hi fedor, this is not what i asked. I need to stream image from url to imageview continuously.sorry my english is poor.thank you for reply
Praveenb
+1  A: 

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
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
+1  A: 

@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