如何回复和更新正确的通知

时间:2019-07-01 13:52:32

标签: android push-notification

问题:回复通知时,我总是会得到上一个通知ID,它会更新上次创建的通知,即使我回复第一个或最后一个创建的通知也是如此。

因此,当我更新notif_1时,我已经更新了notif_4(最后一个notif)

所以当我更新notif_2时,我更新了notif_4(最后一个notif)

我想要的是当我回复notif_1时,不从其他notif更新notif_1

public static void setAndUpdateNotificationMessage(Context context, CharSequence[] history, CharSequence message, CharSequence title) {

        String replyLabel = ("Your message here...");
        RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
                .setLabel(replyLabel)
                .build();
        Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
//        replyIntent.putExtra(KEY_MESSAGE_ID, 1);
        replyIntent.setAction(REPLY_ACTION);
        replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent replyPendingIntent =
                PendingIntent.getBroadcast(context,
                        requestCode,
                        replyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action action =
                new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
                        ("Reply"), replyPendingIntent)
                        .addRemoteInput(remoteInput)
                        /*for wear watch notification*/
                        .setAllowGeneratedReplies(true)
                        /*for wear watch notification*/
                        .build();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_stat_name)
                .setContentTitle(title)
                .setContentText(message)
                .addAction(action)
                .setGroup(GROUP_KEY_WORK_EMAIL)
                .setPriority(Notification.PRIORITY_DEFAULT);
        if(history != null) {
                builder.setRemoteInputHistory(history);
        }

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);


        notificationManager.notify(id, builder.build());

0 个答案:

没有答案