Как сделать так, чтобы мое уведомление оставалось наверху? - PullRequest
0 голосов
/ 26 мая 2020

У меня есть уведомление в стиле медиа, которое показывает, когда медиа-сервис запускается на переднем плане. Я бы хотел, чтобы это уведомление всегда оставалось поверх всех других уведомлений. Я установил приоритеты для каналов и уведомлений на ВЫСОКИЙ и МАКСИМАЛЬНЫЙ, но уведомление даже не отображается сверху, оно отображается под некоторыми старыми уведомлениями ...

Вот мой метод 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);
...