【问题标题】:New notification should not cancel the previous notification in android新通知不应取消android中的先前通知
【发布时间】:2015-07-16 08:15:28
【问题描述】:

感谢观看。当通知被触发时,我不想用新的通知替换以前的通知。就我而言,通知正在被替换。仅当用户按下 android 内置的清除通知选项时,才应清除通知。感谢小伙伴们的帮助。

这就是我尝试过的:

  Intent notifyIntent =
                    new Intent(new Intent(this, Dashboard_DrawerMain.class));
// Sets the Activity to start in a new, empty task
            notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );

            contentIntent = PendingIntent.getActivity(this, 0,notifyIntent
                   , 0);

            mBuilder =
                    new NotificationCompat.Builder(this)

                                    .setContentTitle(str_SenderName)
                                    .setStyle(new NotificationCompat.BigTextStyle())
                                    .setContentText(str_Message)
                                    .setAutoCancel(true);



               mBuilder.setSmallIcon(R.drawable.ft_icon);


            mBuilder.setContentIntent(contentIntent);
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

【问题讨论】:

  • 你用谷歌搜索了吗?您至少阅读过NotificationManager.notify 文档吗?
  • @Selvin 谷歌?什么是谷歌?

标签: android android-notifications android-pendingintent


【解决方案1】:

请在 NotificationManager.notify 上使用不同的 NOTIFICATION_ID

【讨论】:

    【解决方案2】:

    如果 NOTIFICATION_ID 是唯一的,那么系统会将其视为新通知

       mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    

    但如果只是对之前通知的更新,最好更换通知

    【讨论】:

      【解决方案3】:

      使用新 ID 创建新通知,它不会清除之前的通知。

      【讨论】:

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