如何回复合适的用户并更新合适的通知。
发送消息后,应用程序会使用notification -> id
= id(from sender)
创建通知,以便为每个发送消息的用户发出不同的通知。那是一个好的实现吗?以及当我回复某些通知时,您如何建议解决该问题,回复适当的用户并更新正确的通知。我认为我还需要为请求代码使用相同的ID,但仅适用于最后收到的通知,因为最后收到的消息会覆盖notification -> id
。当我单击答复并像请求代码一样使用它时,是否可以从通知中获取ID。您能建议我还是给我一些例子,也许我认为方法不正确。
id = userID
requestCode = userID
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());