首页 > 解决方案 > 如何让我的通知保持在最前面?

问题描述

我有一个媒体风格的通知,显示媒体服务何时启动前台。我希望此通知始终位于所有其他通知之上我已将频道和通知优先级设置为 HIGH 和 MAX,但通知甚至没有显示在顶部,它出现在一些较旧的通知下方...

这是我的 createChannel 方法:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = "Notification channel name";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
            channel.setSound(null, null);
            channel.setDescription("Notification channel description");
            channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            // Enregister le canal sur le système : attention de ne plus rien modifier après
            NotificationManager notificationManager = getSystemService(NotificationManager.class);
            Objects.requireNonNull(notificationManager).createNotificationChannel(channel);
        }

和通知:

  Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)

                .setContentTitle(chanson)
                .setContentText(artiste)
                .setLargeIcon(icone)
                .setSmallIcon(R.drawable.ic_stat_name)
                .setContentIntent(pendingIntent)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .addAction(R.drawable.ic_pause, "pause", pausePendingIntent)
                .setOngoing(true)
                .setStyle(new androidx.media.app.NotificationCompat.MediaStyle())
                .build();

        startForeground(1, notification);

标签: javaandroidnotificationschannel

解决方案


推荐阅读