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
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).
To add an image in your notification, pass an instance of NotificationCompat. BigPictureStyle to setStyle() .
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);
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
You can design a custom notification, instead of just the default notification view of header and sub-header.
What you want is here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With