how to download All File from Arraylist in android? -
i want download video , save in sdcard.i have arraylist in file.not single file.how possible .please help me.
arraylist<url_dto> list = new arraylist<url_dto>();
thanks in advance!!!
what pass param in downloadfilefromurl().i used button click event.
maindownloadbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //what pass param new downloadfilefromurl().execute(); } });
may download class in below ::
class downloadfilefromurl extends asynctask<object, string, string> { int count = 0; progressdialog dialog; progressbar progressbar; int myprogress; /** * before starting background thread show progress bar dialog * */ @override protected void onpreexecute() { super.onpreexecute(); progressbar progressbar; } /** * downloading file in background thread * */ @override protected string doinbackground(object... params) { log.v("log_tag", "params :::; " + params); int count; progressbar = (progressbar) params[0]; seek { // url url = new url(f_url[0]); url url = new url((string) params[1]); log.v("log_tag", "name ::: " + url); name = ((string) params[1]).substring(((string) params[1]) .lastindexof("/") + 1); log.v("log_tag", "name substring ::: " + name); urlconnection conection = url.openconnection(); conection.connect(); // getting file length int lenghtoffile = conection.getcontentlength(); // input stream read file - 8k buffer inputstream input = new bufferedinputstream(url.openstream(), 8192); download = new file(environment.getexternalstoragedirectory() + "/download/"); if (!download.exists()) { download.mkdir(); } string strdownloadurl = download + "/" + name; log.v("log_tag", " downwards url " + strdownloadurl); fileoutputstream output = new fileoutputstream(strdownloadurl); byte data[] = new byte[1024]; long total = 0; while ((count = input.read(data)) != -1) { total += count; // publishing progress.... // after onprogressupdate called // publishprogress("" + (int) ((total * 100) / // lenghtoffile)); // writing info file progressbar .setprogress((int) ((total * 100) / lenghtoffile)); output.write(data, 0, count); } // flushing output output.flush(); // closing streams output.close(); input.close(); } grab (exception e) { log.e("error: ", e.getmessage()); } homecoming null; } /** * updating progress bar * */ protected void onprogressupdate(string... values) { super.onprogressupdate(values); log.v("log_tag", "progress :: " + values); // setting progress percentage // pdialog.setprogress(integer.parseint(progress[0])); } /** * after completing background task dismiss progress dialog * **/ protected void onpostexecute(string file_url) { log.v("log", "login ::: 4::: " + download); string videopath = download + "/" + name; string chpname = name; log.v("log_tag", "chpname ::::" + chpname + " videopath " + videopath); db.execsql("insert videostatus (chapterno,videopath) values(\"" + chpname + "\",\"" + videopath + "\" )"); } }
this link provides thought on http file download. idea, can iterate through video urls in list.
android arraylist download
No comments:
Post a Comment