Java 如何在下面的牛轧糖版本(如whatsapp)中设置回复操作?

Java 如何在下面的牛轧糖版本(如whatsapp)中设置回复操作?,java,android,Java,Android,我正在尝试设置push通知中的reply操作,就像Whatsapp一样。如何显示弹出窗口,如whatsapp,以便在推送通知中回复 单击回复时,我必须打开一个如下图所示的对话框。 直接回复可在安卓N或更高版本的设备上使用 首先,您需要构建可以传递到NotificationBuilder的远程输入 RemoteInput remoteInput = new RemoteInput.Builder(KEY_INLINE_REPLY) .setLabel("Response") .bu

我正在尝试设置
push通知中的
reply
操作,就像
Whatsapp
一样。如何显示弹出窗口,如
whatsapp
,以便在
推送通知中回复

单击回复时,我必须打开一个如下图所示的对话框。

直接回复可在安卓N或更高版本的设备上使用

首先,您需要构建可以传递到NotificationBuilder的远程输入

RemoteInput remoteInput = new RemoteInput.Builder(KEY_INLINE_REPLY)
    .setLabel("Response")
    .build();
然后您可以创建通知

NotificationCompat.Action replyAction =
  new NotificationCompat.Action.Builder(android.R.drawable.ic_custom_icon,"Respond", respondPendingIntent)
    .addRemoteInput(remoteInput)
    .build();
nofitication.addAction(replyAction);
接下来,我们需要检索输入。在由挂起的意图(例如活动或服务)启动的组件中,远程输入在意图上可用。使用构建远程输入时使用的相同密钥访问用户输入:

Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null) {
    CharSequence reply = remoteInput.getCharSequence(KEY_INLINE_REPLY);
    //do something awesome with the reply
}
输入回复后,将显示一个进度微调器,以指示正在发生某些事情。一旦回复得到处理,您就可以停止微调器。至少有两种方法可以解决这个问题: 通过调用Cancel取消通知 重新发出通知,并包含更新的消息(例如“成功回复”)

您应该添加向后兼容性

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    //we are running Nougat
    respondIntent = new Intent(context, NotificationIntentService.class);
    respondPendingIntent = PendingIntent.getService(context, 0, respondIntent, PendingIntent.FLAG_CANCEL_CURRENT);
} else {
    //we are running a version prior to Nougat
    respondIntent = new Intent(context, MainActivity.class);
    respondPendingIntent = PendingIntent.getActivity(context, 0, respondIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}

您可以在此处查看更多信息

请先阅读。仅供参考,这是一个对话主题的活动,不是对话。谢谢你的回复。但我实现了牛轧糖版本的直接回复,但我也尝试在较低版本中实现同样的回复。。类似于窗口管理器的东西。那么有人会帮助whatsapp如何在下面的牛轧糖版本中实现回复选项吗。