1

I have found one answer here:

Pin Notification to top of notification area

Does anyone known what the Vaiden's answer means?

notification.when = previousTimestamp;

How to get the "previousTimestamp"?

Thanks.

Community
  • 1
  • 1
Geek4IT
  • 592
  • 5
  • 13

1 Answers1

0

Vaiden means to make up timestamps for all of your notifications in the order you want them to appear in. Give a more recent timestamp for the ones that you want to have appear up top. The key point is that in the following example, previousTimestamp does not change, as opposed to constantly updating it with the current system time on every refresh (in the case of the question you are referring to, every 3 seconds).

set the following on all of your notifications:

myNotification.when = previousTimestamp;

not

myNotification.when = System.currentTimeMillis();

EDIT: Besides Vaiden's method, there are two things you can do to move your notifications up.

  1. You can set the following two flags on your notification to make it ongoing, keeping it above non-ongoing notifications. Keep in mind that notifications that the user would expect to be able to clear, such as an email notification, should not use this method.

    myNotification.flags |=      
    Notification.FLAG_ONGOING_EVENT;  
    myNotification.flags |= Notification.FLAG_NO_CLEAR;
    
  2. You can set the notification priority to a higher level of you are developing for Android 4.1 Jelly Bean and above. They are MAX, HIGH, DEFAULT, LOW, and MIN. If your app runs below Jelly Bean as well, then the priority is just default. See http://developer.android.com/design/patterns/notifications.html for more details on what priority is appropriate for which type of notification, but just remember, as with the ongoing flag, don't abuse the high priority setting.

    NotificationCompat.setPriority(PRIORITY_MAX);
    
  • Oh, I see, it seems that this only works well with all of my notifications, do you known how to pin to the top of all notifications include others? – Geek4IT Jul 23 '14 at 11:00
  • From my research (on the Android developers' website, StackOverflow, and other websites), I have concluded that that is impossible. The most you can do is to set your notification to ongoing using the code found in the question that you linked to (specifically, the following two flags: FLAG_ONGOING_EVENT and FLAG_NO_CLEAR). These will keep your notifications from being cleared unless the app is closed, and will keep them above clearable notifications. – Samuel Rabinowitz Jul 23 '14 at 21:32
  • But apps such as Clean Master,their notification has very high priority. – Geek4IT Jul 24 '14 at 11:59
  • The ongoing part I mentioned in my previous comment should keep it above every notification that is not ongoing. I will look into the possibility of a priority setting for notifications. – Samuel Rabinowitz Jul 24 '14 at 12:30
  • I have an app with multiple downloads, showing each progress in separate notification. I tried to solve the issue with notifications jumping over each other with this solution, but I couldn't make it work. If I take the **startTime** when creating notification and set **when** to **startTime** with progress update, like this: `ntfBuilder.setProgress(count, last, false).setWhen(startTime);` my notifications still jumping over each other. I don't need to keep them on top of other notifications. Just need to stop them to stay in same order. – Liphtier Dec 13 '16 at 15:37