0
我在更新通知內容時沒有在通知窗口內重新排列時遇到問題。如何正確更新通知內容?
官方文檔說只要notification ID
和TAG
是相同的,通知應該被替換。這正是發生的情況,除了一個問題 - 每次更新它時它都會被推到列表的頂部(除非優先級設置爲LOW
或MIN
,我不想這麼做)。
通過使用setDefaults()
未在構建器上設置任何默認值來發布無提示通知會有訣竅,但這又不是必需的。
我在做什麼錯?我知道這是可能的,因爲Gmail應用程序可以將其通知更改爲「撤消」,而無需重新排列。
下面是我使用的代碼:
void showFirstNotif(){
mNotifBuilder.setContentTitle("First")
.setContentText("Body")
.setWhen(activityStartTime)
.setSmallIcon(PhotoUtils.getAppIconResId())
.setDefaults(Notification.DEFAULT_ALL)
.setOnlyAlertOnce(true);
NotificationManagerCompat.from(this).notify("Test", NOTIF_ID, mNotifBuilder.build());
}
void showSecondNotif(){
mNotifBuilder.setContentTitle("Second")
.setContentText("Body")
.setWhen(activityStartTime)
.setSmallIcon(PhotoUtils.getAppIconResId())
.setDefaults(Notification.DEFAULT_ALL)
.setOnlyAlertOnce(true);
NotificationManagerCompat.from(this).notify("Test", NOTIF_ID, mNotifBuilder.build());
}
沒有。我之前已經嘗試過,只需設置必須更新的屬性。沒有工作:( – Saket
Ohkay,謝謝你! – Saket
@Saket我已經更新了我的答案,看看。 – CodeWarrior