Generate int unique id as android notification id

后端 未结 7 556
难免孤独
难免孤独 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:31

    For anyone still looking around. I generated a timestamp and used it as the id.

    import java.util.Date;
    import java.util.Locale;
    
    public int createID(){
       Date now = new Date();
       int id = Integer.parseInt(new SimpleDateFormat("ddHHmmss",  Locale.US).format(now));
       return id;
    }
    

    Use it like so

    int id = createID();
    mNotifyManager.notify(id, mBuilder.build());
    

提交回复
热议问题