1

Does anyone know how to show a progress bar update in notification bar while downloading a file?

    Context context = MyClass.this.getApplicationContext();
    NotificationManager notificationManager = (NotificationManager) 
                                context.getSystemService(NOTIFICATION_SERVICE);
    Notification updateComplete = new Notification();
    updateComplete.icon         = R.drawable.ic_launcher;
    updateComplete.tickerText   = "Starting to download...";
    updateComplete.when         = System.currentTimeMillis();
    Intent notificationIntent   = new Intent(context, MyClass.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                                                        notificationIntent, 0);
    String contentTitle         = "Download"; 
    updateComplete.setLatestEventInfo
                      (context, contentTitle, "downloading...", contentIntent);
    notificationManager.notify("yyy",1, updateComplete);
belladonna
  • 175
  • 2
  • 11
  • I reverted the [suggested edit](http://stackoverflow.com/review/suggested-edits/1999128#./1999128) because it was invalid. Folks, if you suggest edits, why do you change strings? This makes no sense. And changing personal formatting preferences is really also a waste of time. – class stacker Apr 26 '13 at 09:04

2 Answers2

1

Here's a sample that should help you : http://developer.android.com/training/notify-user/display-progress.html

Ashwini Bhangi
  • 291
  • 1
  • 6
  • Thanks! But Im having an error with .setProgress it says "The method setProgress(int, int, boolean) is undefined for the type NotificationCompat.Builder". And also with the mBuilder.build() "The method build() is undefined for the type NotificationCompat.Builder" – belladonna Apr 27 '13 at 02:57
  • which is the android version you want your app on ? Also have you added in the support library ? – Ashwini Bhangi Apr 27 '13 at 08:26