android - How to get sofar downloaded byte? -


i use library downloading files , awesome library , need sofar downloaded byte (its parameter of progress) in oncreate updating progress bar in oncreate.

this code :

public class mainactivity extends appcompatactivity {      private button btndownload;     private progressbar prgdownload;     private int downloadid;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          ////////////////////////////////////////////////////////////         //================== init views  ===========         ////////////////////////////////////////////////////////////          btndownload = (button) findviewbyid(r.id.btndownload);         prgdownload = (progressbar) findviewbyid(r.id.prgdownload);         final string savepath = filedownloadutils.getdefaultsaverootpath() + file.separator + "angry.apk";         final string url = "http://dl2.soft98.ir/mobile/angry.birds.rio.2.6.1_soft98.ir.apk";            ////////////////////////////////////////////////////////////         //================== init download manager  ===========         ////////////////////////////////////////////////////////////          btndownload.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 downloadid = createdownloadtask(url,savepath).start();             }         });      }      ////////////////////////////////////////////////////////////     //================== start download manager  ===========     ////////////////////////////////////////////////////////////      private basedownloadtask createdownloadtask(final string url , final string savepath){         return filedownloader.getimpl().create(url)                 .setpath(savepath)                 .setlistener(new filedownloadlistener() {                       @override                     protected void pending(basedownloadtask task, int sofarbytes, int totalbytes) {                         toast.maketext(mainactivity.this, "we in pending ... ", toast.length_short).show();                     }                      @override                     protected void started(basedownloadtask task) {                         super.started(task);                     }                      @override                 =====>    protected void progress(basedownloadtask task, int sofarbytes, int totalbytes) {                         prgdownload.setmax(totalbytes);                         prgdownload.setprogress(sofarbytes);                         btndownload.settext("stop");                         btndownload.setonclicklistener(new view.onclicklistener() {                             @override                             public void onclick(view v) {                                 filedownloader.getimpl().pause(downloadid);                             }                         });                      }                      @override                     protected void completed(basedownloadtask task) {                         toast.maketext(mainactivity.this, "download completed !!!", toast.length_short).show();                         btndownload.settext("open");                     }                      @override                     protected void paused(basedownloadtask task, int sofarbytes, int totalbytes) {                         btndownload.settext("resume");                         btndownload.setonclicklistener(new view.onclicklistener() {                             @override                             public void onclick(view v) {                                 createdownloadtask(url, savepath).start();                                 toast.maketext(mainactivity.this, "resume", toast.length_short).show();                             }                         });                      }                      @override                     protected void error(basedownloadtask task, throwable e) {                         toast.maketext(mainactivity.this, "we have error !!!", toast.length_short).show();                      }                      @override                     protected void warn(basedownloadtask task) {                         toast.maketext(mainactivity.this, "we have warn !!!", toast.length_short).show();                      }                 });       }      @override     protected void ondestroy() {         super.ondestroy();         filedownloader.getimpl().pause(downloadid);     } } 


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -