android - updating notification progress failed why? -


my issue cannot update notification information, such progress bar or text, asynctask.

i've spent quite time on issue, found no solution. aim able change dialog progress bar , text.

how can make notification progress bar work?

here code:

private class excuteuploadfile extends         asynctask<httpresponse, integer, httpresponse> {      long totalsize;     int notification_id;     string filepath, filename;     string serverresponse = null;     string urlserver = "http://myurl";     notificationmanager mnotifymanager;     builder mbuilder;     progressdialog pd;     boolean nofti_appended = false;     jsonobject jsonfile = null;      public excuteuploadfile(string filepath, string filename) {         this.filepath = filepath;         this.filename = filename;          log.i("uploader", "selected file name : " + filename);         log.i("uploader", "selected file path : " + filepath);      }      @override     protected void onpreexecute() {         pd = new progressdialog(babupmain.this);         // pd.setmessage(getresources().getstring(r.string.uploading_file));         pd.settitle(filename);         pd.setprogressstyle(progressdialog.style_horizontal);         pd.setcancelable(false);         pd.seticon(android.r.drawable.ic_menu_upload);         pd.setbutton(dialoginterface.button_negative,                 getresources().getstring(r.string.cancel),                 new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                         dialog.dismiss();                         cancel(true);                     }                 });         // hide button         pd.setbutton(dialoginterface.button_neutral,                 getresources().getstring(r.string.hide),                 new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                          dialog.dismiss();                         random r = new random();                         notification_id = r.nextint(80 - 65) + 1;                         notification_id++;                         mnotifymanager = (notificationmanager) getsystemservice(context.notification_service);                         mbuilder = new notificationcompat.builder(                                 babupmain.this);                         mbuilder.setcontenttitle(filename)                                 .setcontenttext(                                         getresources().getstring(                                                 r.string.uploading_file))                                 .setongoing(true)                                 .setsmallicon(android.r.drawable.ic_menu_upload);                         mbuilder.setprogress(100, 100, true);                         mnotifymanager.notify(notification_id, mbuilder.build());                         nofti_appended = true;                     }                 });          pd.show();     }      @override     protected httpresponse doinbackground(httpresponse... arg0) {         httpclient httpclient = new defaulthttpclient();         httpcontext httpcontext = new basichttpcontext();         httppost httppost = new httppost(urlserver);          try {             log.i("uploader", "started " + filename);              if (iscancelled()) {                 og.i("uploader", "uploading has been canceled");             }              custommultipartentity multipartcontent = new custommultipartentity(                     new progresslistener() {                         @override                         public void transferred(long num) {                             publishprogress((int) ((num / (float) totalsize) * 100));                             log.i("uploader", "uploading " + num + " of "                                     + totalsize);                         }                     });              multipartcontent.addpart("file", new filebody(new file(filepath)));             totalsize = multipartcontent.getcontentlength();             log.i("uploader", "bytes send " + totalsize);             // send             httppost.setentity(multipartcontent);             httpresponse response = httpclient.execute(httppost, httpcontext);             serverresponse = entityutils.tostring(response.getentity());              log.i("uploader", "server response : " + serverresponse);              return null;          } catch (exception e) {              log.i("uploader", "uploading error : " + e.getmessage());         }         return null;     }      @override     protected void oncancelled() {         super.oncancelled();          if (nofti_appended) {             mnotifymanager.cancel(notification_id);         } else {             pd.dismiss();         }     }      @override     protected void onprogressupdate(integer... progress) {          if (nofti_appended == true) {             mbuilder.setprogress(100, progress[0], false);         } else {             pd.setprogress((int) (progress[0]));         }      }      @suppresswarnings("deprecation")     @override     protected void onpostexecute(httpresponse ui) {          log.i("uploader", "done: " + filename);      }  } 


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -