我每 1/2 小时向我的 Android 应用程序发送一次 C2DM 更新,这会创建一个通知。问题是,当我早上醒来时,状态栏中有 15 个通知在排队。
如何只保留最新的通知,覆盖以前的通知?
我试着查看 C2DM 文档 ( http://code.google.com/android/c2dm/ ),其中提到了一个名为 collapse_key 的参数,但我找不到关于如何使用它的解释,我也不确定解决方案是否在 C2DM 方面。
谢谢!
最佳答案
如果你想取消之前在 View 上设置的任何通知,你可以尝试设置这些标志之一。
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_UPDATE_CURRENT
我相信这样的东西应该取代你的旧通知
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);
关于android - 如何折叠 Android 通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3740103/