Можно ли использовать InboxStyle и BigText как в одном уведомлении - PullRequest
0 голосов
/ 01 июня 2018

Я создал уведомление с помощью

NotificationCompat.InboxStyle

и добавил текст, используя

inboxStyle.addLine

для нескольких текстовых сообщений.Но я, когда я добавил

Notification.BigTextStyle

в уведомление, BigTextStyle не работает из-за уведомления уже setStyle.

Мое уведомление:

Notification summaryNotification = new
NotificationCompat.Builder(this, notificationChannelId)
                    .setContentTitle("title")
                    .setStyle(addInboxStyle())
                    .setStyle(addBigTextStyle())
                    .setGroupSummary(true)
                    .setContentIntent(pendingIntent)
                    .setChannelId(notificationChannelId)
                    .build();

1 Ответ

0 голосов
/ 12 апреля 2019

нет, это невозможно, но вы можете получить аналогичное поведение с помощью уведомления MessagingStyle, вы можете использовать большие сообщения без расширения и с расширением уведомления, а также вы можете иметь несколько строк в уведомлении

https://developer.android.com/reference/android/app/Notification.MessagingStyle

NotificationCompat.MessagingStyle.Message message1 =
        new NotificationCompat.MessagingStyle.Message(messages[0].getText(),
                                                      messages[0].getTime(),
                                                      messages[0].getSender());
NotificationCompat.MessagingStyle.Message message2 =
        new NotificationCompat.MessagingStyle.Message(messages[1].getText(),
                                                      messages[1].getTime(),
                                                      messages[1].getSender());

Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.new_message)
        .setStyle(new NotificationCompat.MessagingStyle(resources.getString(R.string.reply_name))
                .addMessage(message1)
                .addMessage(message2))
        .build();
...