Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress bar in notification bar when uploading image?

Tags:

android

I'd like my app to upload an image to a web server. That part works.

I'm wondering if it's possible to somehow show the progress of the upload by entering an entry in the "notification bar". I see the Facebook app does this.

When you take a picture and choose to upload, the app lets you continue on, and somehow puts the picture upload notifications in a progress bar in the notification bar. I think that's pretty slick. I guess they spawn a new service or something to handle the upload and update that progress bar in the notification bar every so often.

Thanks for any ideas

like image 929
Mark Avatar asked Dec 09 '09 04:12

Mark


People also ask

How do I show progress bar in notification?

To display a determinate progress bar, add the bar to your notification by calling setProgress(max, progress, false) and then issue the notification. The third argument is a boolean that indicates whether the progress bar is indeterminate (true) or determinate (false).

How do I add an image to my notification bar?

To add an image in your notification, pass an instance of NotificationCompat. BigPictureStyle to setStyle() .

How can I add progress bar in Android?

In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this);


2 Answers

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

like image 187
Paolo Rovelli Avatar answered Sep 19 '22 21:09

Paolo Rovelli


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

What you want is here

like image 22
Eric Mill Avatar answered Sep 20 '22 21:09

Eric Mill