简体   繁体   English

如何让通知保持在最前面?

[英]How to make notification stay on top?

I have a notification which I always want to stay on top.我有一个通知,我总是想保持领先。

I have already given it a priority of 2我已经给它一个优先级 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.大多数情况下它保持在顶部,但是,假设有一个开放的 WiFi 网络,那么我的通知就会下降,并且开放 WiFi 网络的通知出现在顶部位置。

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.但是当我查看 vlc(for Android) 支付歌曲的通知时,vlc 的通知保持在顶部并且打开 WiFi 网络的通知下降。

I notification is ongoing and with priority 2. I 通知正在进行中,优先级为 2。

What should I do.我该怎么办。 I am a beginner so please bear with me.我是初学者,所以请多多包涵。

And thanks in advance.并提前致谢。

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优先级 --> 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://material.google.com/patterns/notifications.html#correctly_set_and_manage_notification_priority

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

and as StenSoft said Android: How to create an "Ongoing" notification?正如 StenSoft 所说的Android:如何创建“正在进行的”通知?

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM