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
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
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.
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
@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();
}
}