1

I have a notification which I always want to stay on top.

I have already given it a priority of 2

Mostly it stays on top but, suppose there is a open WiFi network, then my notification goes down and the notification of open WiFi network comes on the top position.

But when I looked at the notification of vlc(for Android) paying a song, the notification of vlc stay on top and the notification of open WiFi network goes down.

I notification is ongoing and with priority 2.

What should I do. I am a beginner so please bear with me.

And thanks in advance.

madhan kumar
  • 1,560
  • 2
  • 26
  • 36
Hokkyokusei
  • 1,021
  • 13
  • 18

2 Answers2

4

have you tried this

NotificationCompat.Builder builder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notify_icon)
            .setContentTitle("Notification")
            .setContentText("ON Top")
            .setPriority(Notification.PRIORITY_MAX);

Priority Levels --> PRIORITY_MAX / PRIORITY_HIGH /PRIORITY_DEFAULT /PRIORITY_LOW /PRIORITY_MIN

read https://material.google.com/patterns/notifications.html#correctly_set_and_manage_notification_priority

https://developer.android.com/reference/android/app/Notification.html#priority

and as StenSoft said Android: How to create an "Ongoing" notification?

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88
  • Notification.PRIORITY_MAX always leads to highlight like when you move background to foreground it popup on the app but we can't say it is on the top of the stack. – Kishan Donga Jul 08 '20 at 04:56
0

I think you can refer to this code:

Intent push = new Intent();
    push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    push.setClass(this, NotificationDemo.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, push, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationManager nm=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);

    Notification updateNotification = new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_face_black_24dp)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
            .setContentTitle("Priority Max Notification Title")
            .setContentText("Priority Max Notification Message")
            .setAutoCancel(false)
            .setDefaults(Notification.DEFAULT_SOUND)
            .setPriority(Notification.PRIORITY_MAX)
            .setFullScreenIntent(pi,true)
            .build();



    nm.notify("priorityMaxTest",2,updateNotification);
Vaycent
  • 96
  • 6