Generate int unique id as android notification id

后端 未结 7 540
难免孤独
难免孤独 2020-12-05 16:37

When I send multiple push notifications, I need them to be all shown in the notification bar ordered by the time sent desc. I know I should use unique notification - I tried

7条回答
  •  一整个雨季
    2020-12-05 17:34

    If someone reading this, there is a method here. it is better to specify a tag name also with id, so that it will help if you are bundling the part as a module to share with developers.

    NOTE: The problem with assigning some random integer id is that, if any module or library uses the same id, your notification will be replaced by new notification data.

    // here createID method means any generic method of creating an integer id
    int id = createID();
    // it will uniqly identify your module with uniq tag name & update if present.
    mNotifyManager.notify("com.packagename.app", id, mBuilder.build());
    

提交回复
热议问题