0
<-- Android/Java --->

private NotificationManager mNotifyManager;
private NotificationCompat.Builder build;
final int id = 101;

private class Download extends AsyncTask<Void, Integer, Integer> {

      @Override
      protected void onPreExecute() {
         super.onPreExecute();

         // Displays the progress bar for the first time.
         build.setProgress(100, 0, false);
         mNotifyManager.notify(id, build.build());
      }

      @Override
      protected void onProgressUpdate(Integer... values) {
         // Update progress
         build.setProgress(100, values[0], false);
         mNotifyManager.notify(id, build.build());
         super.onProgressUpdate(values);
      }

      @Override
      protected Integer doInBackground(Void... params) {
            //.........

                    FileOutputStream f = new FileOutputStream(new File(rootFile,
                            arg0[1]));

                    InputStream in = c.getInputStream();
                    byte[] buffer = new byte[1024];
                    int len1 = 0;
                    float conLen = c.getContentLength();
                    float total = 0;
                    while ((len1 = in.read(buffer)) > 0) {
                        f.write(buffer, 0, len1);
                        total += len1;
                        publishProgress((int) (total * 100 / conLen));
                    }
                    f.close();

         return result;
      }

      @Override
      protected void onPostExecute(Integer result) {
         super.onPostExecute(result);
         Log.e(TAG,"in PostExecute");
         build.setContentText("Download complete");
         // Removes the progress bar
         build.setProgress(0, 0, false);
         mNotifyManager.notify(id, build.build());
      }
   }

}

Problem

Every Think Working Fine But When I am in postExecute Notification not update

Any one gets Where I am going wrong ?

piet.t
  • 11,718
  • 21
  • 43
  • 52
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65
  • 1
    This is what written in android docs for updating notifications.`Caution: Android applies a rate limit when updating a notification. If you post updates to a notification too frequently (many in less than one second), the system might drop some updates.` You are updating notification multiple times in your progress update. That might be the issue. – Vivek Mishra Oct 05 '18 at 10:58
  • any solution to avoid this issue @VivekMishra – Ashvin solanki Oct 05 '18 at 11:00
  • I tink you can remove your notification from progress update method – Vivek Mishra Oct 05 '18 at 11:04
  • then how to show download process in notification ? @VivekMishra – Ashvin solanki Oct 05 '18 at 11:05
  • https://stackoverflow.com/questions/1871515/progress-bar-in-notification-bar-when-uploading-image – Vivek Mishra Oct 05 '18 at 11:07
  • @VivekMishra its not updating but in postExecute i will cancle the notification and angain showing notification with complete lable done – Ashvin solanki Oct 05 '18 at 11:38

2 Answers2

1

From your code it looks like you are using same ids for different notifications so the first notification in onPreExecute() will be showing but the one in onPostExecute() might not show up.

karan
  • 8,637
  • 3
  • 41
  • 78
0

Thanks All Who Help Me I solve it Yesterday

 protected void onPostExecute(Integer result) {
     super.onPostExecute(result);
     DownloadDone();
  }

First I am Cancle My Notification Then Showing Again

public void DonwloadDone()
        {
            mNotifyManager.cancel(id);
            mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            build = new NotificationCompat.Builder(getBaseContext());
            build.setContentTitle("Download")
                    .setContentText("Complete")
                    .setSmallIcon(R.drawable.ic_launcher_foreground);
            Notification notification = build.build();
            mNotifyManager.notify(id, notification);
            sendMyBroadCast("Complete",fx.getPath());

        }
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65