【问题标题】:PendingIntent not working on notificationPendingIntent 不适用于通知
【发布时间】:2016-03-21 09:11:08
【问题描述】:

我正在显示多个通知,每个通知都有自己的 id,因此所有通知都会正确显示。我的问题是当点击最后一个通知时,使用的 PendingIntent 是第一个而不是最后一个。我不明白为什么会发生这种情况,因为我正在使用 FLAG_ONE_SHOT。这是一段代码:

final PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
notificationBuilder.setContentIntent(pendingIntent);

提前致谢!

【问题讨论】:

    标签: android google-cloud-messaging android-pendingintent


    【解决方案1】:

    更改您的待处理意图 ID。用不同的一个代替 0

    【讨论】:

      【解决方案2】:

      使用 Pending Intent 的不同 requestCode 而不是“0”。

      final PendingIntent pendingIntent = stackBuilder.getPendingIntent(your_id, PendingIntent.FLAG_ONE_SHOT);

      【讨论】:

        【解决方案3】:

        如果您想维护所有具有唯一 ID 的通知,那么这可能会对您有所帮助。

        private PendingIntent getContentIntent(String key, Context context, int currentTimeStamp) {
            Intent intent = new Intent();
            intent.setComponent(getComponentName(context));
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            return PendingIntent.getActivity(context, currentTimeStamp, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        }
        

        此方法将返回待处理的意图对象

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多