在NotificationCompat.Builder中使用setPriority()方法设置通知的优先级,以便将其移动到更高的位置。优先级应该在NotificationCompat.PRIORITY_HIGH和NotificationCompat.PRIORITY_MAX之间。
示例代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_MAX);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, builder.build());