【问题标题】:need to open multiple notification in one activity需要在一个活动中打开多个通知
【发布时间】:2018-02-07 09:42:49
【问题描述】:

我已经为我的 android 应用实现了推送通知。我可以在通知栏中显示多个通知,但一次只能显示一个通知。

我认为是标志类型的问题

Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_SINGLE_TOP

PendingIntent.FLAG_CANCEL_CURRENT

这是我的代码,请告诉我我要设置什么类型的标志

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent resultPendingIntent =
PendingIntent.getActivity(
   mContext,
   0,
   intent,
   PendingIntent.FLAG_CANCEL_CURRENT
);

【问题讨论】:

  • 你为演出通知做了什么?
  • 请出示您的通知管理器代码,有问题
  • 另请阅读This
  • 我的解决方案有效吗?

标签: android push-notification android-push-notification


【解决方案1】:

您需要为每个通知使用不同的 ID。如下 : (每次放不同的通知ID)。

您还可以通过以下方式每次创建唯一的通知 ID:

int notiID = (int) System.currentTimeMillis();

PendingIntent.getActivity(
   mContext,
   notiID, //notification ID
   intent,
   0
);

谢谢:)

【讨论】:

  • 我正在尝试:` int NOTIFICATION_ID = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent resultPendingIntent = PendingIntent.getActivity( mContext, NOTIFICATION_ID, intent, 0 ); ` 但所有通知栏都已清除
  • 你试过这个代码吗: int notiID = (int) System.currentTimeMillis(); ??
  • 是的,但是所有通知栏都已关闭,给我发你的电子邮件,我可以给你发我的 NotificationUtils
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 2011-11-28
  • 2011-08-29
  • 1970-01-01
  • 1970-01-01
  • 2013-06-19
相关资源
最近更新 更多