Как я могу сделать нерасширяемое уведомление MediaStyle? - PullRequest
0 голосов
/ 02 мая 2020

Фон

Я использую MediaStyle, чтобы сделать уведомление с помощью встроенных кнопок:

Notification with inline buttons

Проблема

При Android с 4 по 6 уведомление расширяется и иногда по умолчанию отображается в развернутом состоянии. Для моего приложения я не хочу, чтобы уведомление расширялось.

Примеры

Фондовая Android 4

MediaStyle notification in expanded state on Android 4

Фондовая Android 5

MediaStyle notification in expanded state on Android 5

Код

Вот код, который я использую:

new NotificationCompat.Builder(context, NotificationChannels.ID_CONTROLS)
    .setColor(context.getColor(R.color.main))
    .setSmallIcon(R.drawable.app_upright_filled)
    .setContentTitle(context.getText(R.string.app_name_full))
    .setContentText(context.getText(R.string.user_rotation_upright))
    .addAction(
        R.drawable.app_left_side,
        context.getText(R.string.user_rotation_left_side),
        leftSidePendingIntent
    )
    .addAction(
        R.drawable.action_turn_off,
        context.getText(R.string.action_turn_off),
        turnOffPendingIntent
    )
    .addAction(
        R.drawable.app_right_side,
        context.getText(R.string.user_rotation_right_side),
        rightSidePendingIntent
    )
    .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
        .setShowActionsInCompactView(0, 1, 2)
    )
    .build()

Вопрос

Как сделать так, чтобы уведомление всегда отображалось в компактном состоянии на устройствах Android 4-6? Мне нужно использовать MediaStyle, чтобы сделать встроенные кнопки в уведомлении.

...