dropbox api - Android - Downloading File by updating Progress Bar -


i have multiple files in dropbox account. downloading files. want show progress bar percentage when files gets downloaded.the progress bar finishes.i using asynctask downloading files.here code.

public void onpreexecute(){          mdialog = new progressdialog(mcontext);         mdialog.setprogressstyle(progressdialog.style_horizontal);         mdialog.setmax(100);         mdialog.show();     }      public void downloadfiles(string filename){         log.i("item name",filename);         file dir = null;         boolean issdpresent = android.os.environment.getexternalstoragestate().equals(android.os.environment.media_mounted);           if(issdpresent){          file sdcard = environment.getexternalstoragedirectory();          dir = new file (sdcard.getabsolutepath() + "/allsecure");         if (!dir.exists()) {             dir.mkdirs();         }         }else{              dir = mcontext.getdir("users", context.mode_private); //creating internal dir;             if(!dir.exists())             {                  dir.mkdirs();             }               }          file file = new file(dir, filename);         try {             fileoutputstream mfileoutputstream=new fileoutputstream(file);              dropboxfileinfo mdropboxfileinxfo=mapi.getfile(photo_dir + filename, null, mfileoutputstream, null);              } catch (filenotfoundexception e) {             // todo auto-generated catch block             e.printstacktrace();             } catch (dropboxexception e) {             // todo auto-generated catch block             e.printstacktrace();             }     }       protected string doinbackground(string... params) {           sessionutil ses = new sessionutil(mcontext);             androidauthsession session = ses.buildsession();             mapi = new dropboxapi<androidauthsession>(session);           entry entries = null;          try {             system.out.println("mapi " + mapi);             entries = mapi.metadata(photo_dir, 10000, null, true, null);         } catch (dropboxexception e1) {             // todo auto-generated catch block             e1.printstacktrace();         }          (entry e : entries.contents) {             if (!e.isdeleted) {                 //log.i("is folder",string.valueof(e.isdir));                 downloadfiles(e.filename());                  mfilelen = entries.bytes;                 log.i("item name",e.filename());             }         }           return null;     }      protected void onprogressupdate(integer... progress) {      }      @override     protected void onpostexecute(string result) {         mdialog.dismiss();        } 

you need call publishprogress method in doinbackground . need pass progress argument publishprogress method.

for example:

protected string doinbackground(string... params) {           sessionutil ses = new sessionutil(mcontext);             androidauthsession session = ses.buildsession();             mapi = new dropboxapi<androidauthsession>(session);           entry entries = null;          try {             system.out.println("mapi " + mapi);             entries = mapi.metadata(photo_dir, 10000, null, true, null);         } catch (dropboxexception e1) {             // todo auto-generated catch block             e1.printstacktrace();         }          int max = entries.contents.size(); // 2 variables need calculate progress         int current = 0;          (entry e : entries.contents) {             if (!e.isdeleted) {                 //log.i("is folder",string.valueof(e.isdir));                 downloadfiles(e.filename());                  mfilelen = entries.bytes;                 log.i("item name",e.filename());                  current++; //calculate progress                 publishprogress(100 * current / max); //then pass             }         }           return null;     } 

after publishprogress called onprogressupdate invoked.

you need handle progress update

protected void onprogressupdate(integer... progress) {      integer p = progress[0];      mdialog.setprogress(p);      mdialog.setmessage(string.format("%d%%", p)); //if need see progress percentage in dialog's text } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -