gpt4 book ai didi

android - 如何折叠 Android 通知?

转载 作者:太空狗 更新时间:2023-10-29 15:49:32 38 4
gpt4 key购买 nike

我每 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/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com