【问题标题】:How to make notification stay on top?如何让通知保持在最前面?
【发布时间】:2016-10-04 14:24:32
【问题描述】:

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

我已经给它设置了 2 的优先级

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

但是当我查看 vlc(for Android) 付费歌曲的通知时,vlc 的通知停留在顶部,而打开 WiFi 网络的通知则下降了。

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

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

提前致谢。

【问题讨论】:

  • VLC 显示正在进行的通知。
  • 你设置了.setPriority(Notification.PRIORITY_MAX); ?
  • 嗯,是的,但我已经给了它最大值。数值。即 2 作为优先级。是的,我的羞辱也在进行中。

标签: android android-notifications


【解决方案1】:

你试过了吗

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: How to create an "Ongoing" notification?

【讨论】:

  • Notification.PRIORITY_MAX 总是会导致突出显示,例如当您将背景移至前景时,它会在应用程序上弹出,但我们不能说它位于堆栈顶部。
【解决方案2】:

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

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

【讨论】:

  • 好吧,据我所知,最大优先级是 2,我已经给了它。
猜你喜欢
  • 1970-01-01
  • 2011-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-19
相关资源
最近更新 更多