我发送C2DM更新我的Android应用程序每一个半小时,这将创建一个通知。问题是,当我早上醒来,我得到15通知排队在状态栏中。
I'm sending a C2DM update to my Android app every 1/2 hour, which creates a Notification. Problem is, when I wake up in the morning I get 15 Notifications queued up in the status bar.
我如何只保留最新的通知,覆盖previous的呢?
How do I only keep the latest notification, overwriting previous ones?
我试图寻找在C2DM的文档上(http://$c$c.google.com/android/c2dm/),其中提到了一个名为collapse_key参数,但我无法找到如何使用它的说明,我也不是一定的解决之道在于对C2DM侧。
I tried looking at the C2DM documentation (http://code.google.com/android/c2dm/) which mentions a parameter called collapse_key, but I couldn't find an explanation for how to use it, nor am I sure the solution lies on the C2DM side.
谢谢!
如果您想取消任何$ P $已设置的视图pvious通知,你可以尝试设置这些标志之一。
If you want to cancel any previous notifications that has been set on the view you can try setting one of these flags.
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_UPDATE_CURRENT
这样的事情应该取代旧的通知,我相信
Something like this should replace your old notification i believe
NotificationManager mManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this,test.class);
Notification notification = new Notification(R.drawable.icon, "Notify", System.currentTimeMillis());
notification.setLatestEventInfo(this,"App Name","Description of the notification",
PendingIntent.getActivity(this.getBaseContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
mManager.notify(0, notification);