gpt4 book ai didi

android - 如何防止android快捷回复通知卡在loading中?

转载 作者:行者123 更新时间:2023-11-29 16:38:57 24 4
gpt4 key购买 nike

我的应用使用 Android N 的新快速回复功能来快速从固定通知中做笔记,而无需用户打开 Activity 。

但是,我希望在用户发送快速回复消息后将通知重置为初始状态,而不必关闭通知。

这是我的代码:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? createChannel() : "").setSmallIcon(android.R.mipmap.sym_def_app_icon).setContentTitle("My Awesome App").setContentText("Doing some work...").setContentIntent(pendingIntent);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
android.support.v4.app.RemoteInput remoteInput = new RemoteInput.Builder(BookmarkCreatorReceiver.TXT_REPLY).setLabel("Reply").build();

Intent replyIntent = new Intent(this, BookmarkCreatorReceiver.class);
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(this, 0, replyIntent, 0);

NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_dialog_email, "Bookmark", replyPendingIntent).addRemoteInput(remoteInput).build();
NotificationCompat.Action actionQuick = new NotificationCompat.Action.Builder(android.R.drawable.ic_dialog_email, "Quick", replyPendingIntent).build();
builder.addAction(action);
builder.addAction(actionQuick);
}

startForeground(NOTIFICATION_ID, builder.build());

问题在于,一旦用户发送消息并调用 Broadcast 接收器,通知就会像这样停留在加载状态:

enter image description here

如何在不丢弃通知的情况下删除加载消息?

最佳答案

根据 Notifications in Android N blog post :

After you’ve processed the text, you must update the notification by calling notify() with the same id and tag (if used). This is the trigger which hides the Direct Reply UI and should be used as a technique to confirm to the user that their reply was received and processed correctly.

另请注意:

For most templates, this should involve using the new setRemoteInputHistory() method which appends the reply to the bottom of the notification.

这可确保用户看到他们输入的文本已得到妥善处理。

关于android - 如何防止android快捷回复通知卡在loading中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51815139/

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