How to show download file in StatusBar in Android -


i want show download progress in statusbar (notification), write below codes when download file not show fill progress in statusbar show 0 in satusbar!

public class site2_activity extends appcompatactivity {      button download;     textview downloadcount;     progressbar progressbar;      // --- add these variables     private notificationmanager mnotifymanager;     private notificationcompat.builder mbuilder;     // ---      future<file> downloading;      context context;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          // enable global ion logging         ion.getdefault(this).configure().setlogging("ion-sample", log.debug);          setcontentview(r.layout.activity_site2_activity);          download = (button) findviewbyid(r.id.download);         downloadcount = (textview) findviewbyid(r.id.download_count);         progressbar = (progressbar) findviewbyid(r.id.progress);         context = this;          file sdcard = environment.getexternalstoragedirectory();         file dir = new file(sdcard.getabsolutepath() + "/my app");         if (!dir.exists()) {             dir.mkdirs();         }         final file file = new file(dir, "filename.zip");          download.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 if (downloading != null && !downloading.iscancelled()) {                     resetdownload();                     return;                 }                  download.settext("cancel");                  // --- initialize notification manager , builder                 mnotifymanager = (notificationmanager) getsystemservice(context.notification_service);                 mbuilder = new notificationcompat.builder(context);                 mbuilder.setcontenttitle("picture download")                         .setcontenttext("download in progress")                         .setsmallicon(r.mipmap.ic_launcher);                 // ---                  // 180mb zip file test                 downloading = ion.with(context)                         .load("http://cdn.p30download.com/?b=p30dl-software&f=pcwinsoft.1avmonitor.v1.9.1.50_p30download.com.rar")                         .progressbar(progressbar)                         .progresshandler(new progresscallback() {                             @override                             public void onprogress(long downloaded, long total) {                                 downloadcount.settext("" + downloaded + " / " + total);                                  // --- update progress on notification                                 mbuilder.setprogress(100, 0, false);                                 mnotifymanager.notify(0, mbuilder.build());                                 // ---                             }                         })                         // write file                         .write(file)                         // run callback on completion                         .setcallback(new futurecallback<file>() {                             @override                             public void oncompleted(exception e, file result) {                                 resetdownload();                                 if (e != null) {                                     toast.maketext(context, "error downloading file", toast.length_long).show();                                     return;                                 }                                 toast.maketext(context, "file upload complete", toast.length_long).show();                             }                         });             }         });     }      void resetdownload() {         // cancel pending download         downloading.cancel();         downloading = null;          mbuilder.setcontenttext("download complete")                 // removes progress bar                 .setprogress(0, 0, false);         mnotifymanager.notify(0, mbuilder.build());          // reset ui         download.settext("download");         downloadcount.settext(null);         progressbar.setprogress(0);     } } 

how can fix issue? <3


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -