[英]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://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.