如何折叠 Android 通知? [英] How to collapse Android notifications?

查看:38
本文介绍了如何折叠 Android 通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每 1/2 小时向我的 Android 应用发送一次 C2DM 更新,这会创建一个通知.问题是,当我早上醒来时,状态栏中有 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.

如何只保留最新通知,覆盖以前的通知?

How do I only keep the latest notification, overwriting previous ones?

我尝试查看 C2DM 文档(http://code.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.

谢谢!

推荐答案

如果您想取消之前在视图上设置的任何通知,您可以尝试设置这些标志之一.

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);

这篇关于如何折叠 Android 通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆