- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在显示一个带有 RemoteInput
的通知,如下所示:
RemoteInput remoteInput = new RemoteInput.Builder("key_add_note")
.setLabel("add note")
.build();
PendingIntent AddNotePendingIntent =
PendingIntent.getBroadcast(getApplicationContext(),
(int) txn.get_id(),
new Intent(getApplicationContext(), AddNoteBroadcastReceiver.class)
.putExtra(Constants.IntentExtras.STA_TXN_ID, txn.get_id()),
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.ic_action_edit_dark,
"add note", AddNotePendingIntent)
.addRemoteInput(remoteInput)
.build();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationUtil.MISC_CHANNEL_ID)
.setContentTitle("TEST")
.setContentText("add Note")
.setSmallIcon(R.drawable.ic_action_edit_dark)
.setAutoCancel(true)
.addAction(action);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(123456, builder.build());
输出:
点击添加备注后,输入文本并提交我尝试取消这样的通知:
notificationManager.cancel(123456);
它不会取消通知,只是关闭在我的通知下方附加文本的输入字段,如下所示:
为什么这不取消通知?以及如何取消它。
更新:即使有一个带有通知的标签,结果也是一样的
最佳答案
一段时间后,我找到了一个解决方法,绝对不是最优雅的解决方案。我在 Android 9 上遇到了问题,而远程输入的通知被系统设置为不可关闭。解决方法是,在用户输入文字并点击后,我们需要update the notification UI , 使用 setTimeoutAfter()
;即使值低至 1 毫秒,通知也会在几秒钟后被删除,因此该解决方案不是最好的。
fun updateNotification(context: Context, id: Int) {
val notification = NotificationCompat.Builder(context, MY_CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_action_edit_dark)
.setContentText(MY_TEXT)
.setTimeoutAfter(1)
.build()
// show notification. This hides direct reply UI
NotificationManagerCompat.from(context).notify(id, notification)
}
关于android - 取消 remoteInput 不工作的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54219914/
我正在显示一个带有 RemoteInput 的通知,如下所示: RemoteInput remoteInput = new RemoteInput.Builder("key_add_note")
有一个名为 setAllowDataType 的新函数在 RemoteInput.Builder 在 API 26 中。这是做什么用的?我尝试了以下方法: val remoteInput = Remo
我想要实现的目标很容易解释:我希望用户通过语音从列表中选择一个项目并在应用程序中获得结果,就像 RemoteInput.setChoices(遗憾的是它仅供观看)。 下面是需要与 watch 通话的代
我在我的 Android N 通知中使用 RemoteInput。 我想为输入设置最小和最大文本长度限制。 Google Hangouts 做到了这一点(即当用户输入至少 1 个字符时发送按钮启用)。
我在 N Developer Preview 1 上使用 RemoteInput 允许用户输入一些文本作为 Notification 的一部分。它起作用了,但是当用户按下“发送” "按钮,一个不确定的
我有一个具有以下导入的项目类: import android.app.Activity; import android.app.Fragment; import android.app.Notific
过去 1 周以来,我一直被这个问题困扰。我正在尝试导出我的 Android 应用程序以进行最终发布,但在导出时出现以下错误。 Proguard returned with error code 1.
我是一名优秀的程序员,十分优秀!