2010-08-12 7 views
9

J'essaie de créer plusieurs notifications dans mon application. Pour identifier chaque notification de manière unique, je leur ai donné un ID d'identification unique. À la suite de mon code:Android: Gestion de plusieurs notifications

private void updateNotification(int notificationId, int clockStatusID, CharSequence text) { 
//notificationManager.cancel(notificationId); 
// throws up an ongoing notification that the timer is running 
Log.i("TIMERCOUNT", "Notification id: " + notificationId); 
Notification not = new Notification(clockStatusID, // the 
    // icon 
    // for 
    // the 
    // status 
    // bar 
    text, // the text to display in the ticker 
    System.currentTimeMillis() // the timestamp for the 
    // notification to appear 
); 
Intent intent = new Intent(); 
intent.putExtra("notificationID", notificationId); 
intent.setAction("actionstring" + System.currentTimeMillis()); 
intent.setClassName("com.chander.time.android.activities", 
"com.chander.time.android.activities.Tabs"); 


not.setLatestEventInfo(self, 
    getText(R.string.timer_notification_title), 
    getText(R.string.timer_on_notification_text), PendingIntent 
    .getActivity(this, 0, intent, 
     PendingIntent.FLAG_UPDATE_CURRENT)); 

not.flags += Notification.FLAG_ONGOING_EVENT; 
not.flags += Notification.FLAG_NO_CLEAR; 
notificationManager.notify(notificationId, not); 
} 

Problème: Lorsqu'une notification est sélectionnée, l'activité est appelée onglets passer l'intention. Je souhaite accéder à l'unique notificationId de la notification sélectionnée dans les onglets. J'ai essayé intention.putExtra() pour enregistrer le notificationId dans l'intention. Mais, pour les notifications multiples, il écrase le notificationId et renvoie le dernier. Je ne comprends pas pourquoi cela se produit et comment puis-je éviter cet écrasement de notificationId.

Merci, Chander

Répondre

15

j'ai eu la réponse. Les intentions ont été mises en cache dans Pour obtenir, faire une nouvelle intention, il suffit d'ajouter le morceau de code suivant:.

saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); 

Cela rend l'intention unique.

Aussi, quelqu'un m'a suggéré la pièce de code suivante pour rendre l'unique, l'intention:

saveCallIntent.setAction("actionstring" + System.currentTimeMillis()); 

Il na pas me aider, mais pourrait être utile à quelqu'un d'autre.

--Chander

7

il suffit de placer le notificationId au lieu de 0 à pendingIntent.

PendingIntent.getActivity(this, notificationId, intent,PendingIntent.FLAG_UPDATE_CURRENT)); 

L'utilisateur doit également mettre à jour le code suivant avec celui ci-dessus pour le faire fonctionner.

mNotificationManager.notify(notificationId, mBuilder.build()); 
Questions connexes