繁体   English   中英

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

[英]How to make notification stay on top?

我有一个通知,我总是想保持领先。

我已经给它一个优先级 2

大多数情况下它保持在顶部,但是,假设有一个开放的 WiFi 网络,那么我的通知就会下降,并且开放 WiFi 网络的通知出现在顶部位置。

但是当我查看 vlc(for Android) 支付歌曲的通知时,vlc 的通知保持在顶部并且打开 WiFi 网络的通知下降。

I 通知正在进行中,优先级为 2。

我该怎么办。 我是初学者,所以请多多包涵。

并提前致谢。

你试过这个吗

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

优先级 --> PRIORITY_MAX / PRIORITY_HIGH / PRIORITY_DEFAULT / PRIORITY_LOW / PRIORITY_MIN

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

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

正如 StenSoft 所说的Android:如何创建“正在进行的”通知?

我想你可以参考这段代码:

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