Кнопки не отображаются в уведомлении
Я создаю пользовательское уведомление в сервисе (MusicService) и добавляю кнопки следующим образом.
//Notification
Intent notIntent = new Intent(this, MainActivity.class);
notIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendInt = PendingIntent.getActivity(this, 0,
notIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//Play
Intent playIntent = new Intent(this, MusicService.class);
playIntent.setAction(ACTION_PLAY);
PendingIntent pPlayIntent = PendingIntent.getService(this, 1,
playIntent, 0);
//Pause
Intent pauseIntent = new Intent(this, MusicService.class);
pauseIntent.setAction(ACTION_PAUSE);
PendingIntent pPauseIntent = PendingIntent.getService(this, 1,
playIntent, 0);
//Previous
Intent previousSongIntent = new Intent(this, MusicService.class);
previousSongIntent.setAction(ACTION_PREVIOUS);
PendingIntent pPreviousSongIntent = PendingIntent.getService(this, 1,
previousSongIntent, 0);
//Next
Intent nextSongIntent = new Intent(this, MusicService.class);
nextSongIntent.setAction(ACTION_NEXT);
PendingIntent pNextSongIntent = PendingIntent.getService(this, 1,
nextSongIntent,0);
Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true)
.setContentText(songTitle)
.setContentIntent(pendInt)
.setPriority(Notification.PRIORITY_MAX)
.setWhen(0)
.addAction(R.drawable.ic_play_button, "PLAY", pPlayIntent)
.addAction(R.drawable.ic_pause_button, "PAUSE", pPauseIntent)
.addAction(R.drawable.ic_next_button, "NEXT", pNextSongIntent)
.addAction(R.drawable.ic_previous_button, "PREV", pPreviousSongIntent);
Notification notification = builder.build();
startForeground(NOTIFY_ID, notification);
Значки кнопок не отображаются в уведомлении. Используя два пальца и проведите вниз по тексту отображения уведомления (PLAY PAUSE NEXT). Я что-то пропустил?
0 ответов
Использовать MediaStyle
с участием setShowActionsInCompactView
builder.setStyle(androidx.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2))
Полный пример здесь https://code.videolan.org/videolan/vlc-android/-/blob/master/application/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.kt