Question on NotificationManager, setLatestEventInfo() and custom view.

by Jiri » Sat, 24 Oct 2009 00:07:38 GMT


Sponsored Links
 Hello,

I am creating a notification that displayes the progress of downloading 
files. Because I use a custom layout to be displyed in the expanded 
view. This custom view has a progressbar. I first make a call to the 
notification manager that will show the progress bar as being 
indeterminate and display a text "2 / 10" for instance.
Then when the downloading starts i only want to update the prgress bar.

<code>
     private void showNotification(String tickertxt, String displayTxt , 
  int total , int progress , Boolean indeterminate) {

         NotificationManager notifMgr = (NotificationManager) 
this.getSystemService(Service.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
new Intent(this, MainMenu.class), 0);

        // construct the Notification object.
        Notification notif = new Notification();

        notif.flags = Notification.FLAG_ONGOING_EVENT | 
Notification.FLAG_ONLY_ALERT_ONCE;
        notif.tickerText = tickertxt;
        notif.icon = R.drawable.icon;

        RemoteViews nmView = new RemoteViews( getPackageName(), 
R.layout.custom_notification_layout);
        nmView.setProgressBar(R.id.progressbar, total, progress, 
indeterminate);
        nmView.setTextViewText(R.id.TextView01, displayTxt);

        notif.contentView = nmView;

        notif.contentIntent = contentIntent;

         notifMgr.notify(R.layout.custom_notification_layout,  notif);
     }

</code>
So the first call i make when downloads are being prepared is:

showNotification("download..." , "n / n files" , 1 , 1 , false)

then when downloading starts:


showNotification("download..." , "n / n files" , class.getCurrent() , 
class.getTotal() , true)


What is bothering me is that I call the second call quit a lot and thus 
in the showNotification() a lot of objects are instantiated. In the docs 
it talks about  setLatestEventInfo() but this (afaik) cannot be applied 
when using a custom view.
Is this the way it is or is there a better technique.

Jiri



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Link to buy unlocked phone does not work

On the page http://market.android.com/publish/Home, I see:

  Development phones
  As a registered developer, you can purchase an unlocked phone.
  Buy now 

That is wonderful. Thank you, Google!

But then, when I click on the "Buy now" link, the browser bounces off
android.brightstarcorp.com back to the same page. Happens on Chrome,
Firefox and IE.

Anyone had better luck with this?

-arw


--~--~---------~--~----~------------~-------~--~----~

2. error on my Mac 10.4 Power book: cannot execute binary file

While using Eclipse with the Android developers package I get the
following error when I try and run one of the sample programs:  I get
cannot execute binary file; in addition I get when I restart eclipse I
get an error stating "Failed to parse the output of 'adb version'.
I'm a first time user and newbee with this; greatly appreciate the
help.  I have it working fine on one of my Microsoft XP boxes, however
I would rather work with this in my Mac environment.

--~--~---------~--~----~------------~-------~--~----~

3. Android using Pc's Internet over a USB connection

4. Simple Image Application

5. Entering international characters (with diacritics)

6. Group of Android developers

7. How to Handle Event Handlers?