Pin Notification to top of notification area

前端 未结 8 1773
有刺的猬
有刺的猬 2020-12-09 05:35

I have a Notification which is refreshed (i.e. sent) every three seconds. I\'ve set the FLAG_ONGOING_EVENT flag and the FLAG_NO_CLEAR flag so that is always shown. The probl

8条回答
  •  半阙折子戏
    2020-12-09 05:56

    There is a solution that does exactly what you want.

    In the Notification class, there is a public field called when. According to the API:

    The timestamp for the notification. The icons and expanded views are sorted by this key.

    The default behaviour (for code and coders alike :) is to give when the timestamp of the notification:

    notification.when = System.currentTimeMillis();
    

    So - in order to maintain the correct order of notifications, all you need to do is give it a preset timestamp instead:

    notification.when = previousTimestamp;
    

    When you do this with all of your notifications, they maintain their order. I had the same problem as you and solved it this way.

提交回复
热议问题