Progress bar in notification bar when uploading image?

You can design a custom notification, instead of just the default notification view of header and sub-header.

What you want is here


In Android, in order to display a progress bar in a Notification, you just need to initialize setProgress(...) into the Notification.Builder.

Note that, in your case, you would probably want to use even the setOngoing(true) flag.

Integer notificationID = 100;

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

//Set notification information:
Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext());
notificationBuilder.setOngoing(true)
                   .setContentTitle("Notification Content Title")
                   .setContentText("Notification Content Text")
                   .setProgress(100, 0, false);

//Send the notification:
Notification notification = notificationBuilder.build();
notificationManager.notify(notificationID, notification);

Then, your Service will have to notify the progress. Assuming that you store your (percentage) progress into an Integer called progress (e.g. progress = 10):

//Update notification information:
notificationBuilder.setProgress(100, progress, false);

//Send the notification:
notification = notificationBuilder.build();
notificationManager.notify(notificationID, notification);

You can find more information on the API Notifications page: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Progress

Tags:

Android