gpt4 book ai didi

android - 取消 remoteInput 不工作的通知

转载 作者:太空狗 更新时间:2023-10-29 14:36:37 25 4
gpt4 key购买 nike

我正在显示一个带有 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());

输出:

notification

点击添加备注后,输入文本并提交我尝试取消这样的通知:

notificationManager.cancel(123456);

它不会取消通知,只是关闭在我的通知下方附加文本的输入字段,如下所示:

enter image description here

为什么这不取消通知?以及如何取消它。

更新:即使有一个带有通知的标签,结果也是一样的

最佳答案

一段时间后,我找到了一个解决方法,绝对不是最优雅的解决方案。我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com