Update android notification with new line is removing previous lines

后端 未结 1 659
鱼传尺愫
鱼传尺愫 2021-01-23 00:58

I want to group notifications into a summary.

I achieve this by having a single ID for all notifications. This way android will not create new notifications but update

相关标签:
1条回答
  • 2021-01-23 02:01

    I think you are misinterpreting the notification builder.

    The NotificationCompat.Builder builds the complete notification, with all the content. Reusing the same id simply tells the notification manager to replace an existing notification with the same id with the new one: (Source)

    [...] update or create a NotificationCompat.Builder object, build a Notification object from it, and issue the Notification with the same ID you used previously. If the previous notification is still visible, the system updates it from the contents of the Notification object.

    Thus addLine is not an operation that is performed on an existing notification, but on the new builder you created (which is empty at that time).

    If you want to add a line to an existing notification with the inbox style, you will need to either

    • keep the original builder object, add lines as needed and resend the notification with the same id
    • create a new builder and add the old lines first, then the new one. You will need to store or retrieve the old lines from somewhere (depending on your application).
    0 讨论(0)
提交回复
热议问题