将直接回复与Android通知配合使用,并在RemoteInput
中写出答复(如果出现新通知),则会隐藏当前通知和键盘(如果已打开)。如何避免隐藏起来?理想的解决方案是仅在用户单击RemoteInput之后忽略通知,然后在用户发送消息或取消消息后再次开始显示通知。
String replyText = "Reply";
RemoteInput remoteInput = new RemoteInput.Builder(MyIntentService.EXTRA_TEXT_REPLY)
.setLabel(replyText)
.build();
Intent intent = new Intent(context, MyMessageReplyReceiver.class);
intent.setAction(MyIntentService.ACTION_MESSAGE_TEXT_REPLY);
intent.putExtra(MyIntentService.EXTRA_NOTIFICATION_ID, notificationId);
intent.putExtra(MyIntentService.EXTRA_CHANNEL_ID, channelId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context,
1001,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
R.drawable.ic_reply_bubble, replyText, pendingIntent)
.addRemoteInput(remoteInput)
.build();
builder.setWhen(lastMessage.getTimestamp())
.setShowWhen(true)
.setSmallIcon(R.drawable.notification_bar_message)
.setColor(getNotificationColor())
.setAutoCancel(true)
.setCategory(Notification.CATEGORY_MESSAGE)
.setGroup(GROUP_NOTIFICATIONS)
.addAction(replyAction);
notificationManager.notify(notificationId, builder.build());