2012年7月17日 星期二
An android AsyncTask class to download image from url
it is easy to store web image to local sd card by using apaceh common io...
class initCatalogAsync extends AsyncTask<String, String, String>{
@Override
protected void onPreExecute() {
showDialog(0);
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
for(int i=0; i< videoList.size(); i++){
VideoObj vo= (VideoObj)videoList.get(i);
String thumbsUrl=GlobalConfig.YOUTUBE_THUMBS_URL+vo.getVid()+"/"+GlobalConfig.THUMBS_ID;
File f= new File(GlobalConfig.THUMBS_FOLDER+vo.getVid()+".jpg");
if(!f.exists()){
try {
if(GlobalConfig.DEBUG){
Log.w(TAG,thumbsUrl);
}
FileUtils.copyURLToFile(new URL(thumbsUrl),f);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
@Override
protected void onProgressUpdate(String... progress) {
super.onProgressUpdate(progress);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
setListData();
progressDialog.dismiss();
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言