0

我已经尝试过\n,但它仍然有效,但它不起作用。贝娄是我的代码:

val channelId = resources.getString("NotificationChannelID")

createNotificationChannel("NotifactionChannelName", channelId)

val pendingIntent: PendingIntent =
        Intent(this, MainActivity::class.java).let { notificationIntent ->
               PendingIntent.getActivity(this, 0, notificationIntent, 0)
        }
        val notification = Notification.Builder(this, channelId)
                .setContentText("First Line \n Second Line \n")
                .setSmallIcon(R.drawable.notification_icon)
                .setContentIntent(pendingIntent)
                .build()

        startForeground(NOTIFICATION_MANAGER_NOTIFICATION_ID, notification)



       for(e in error.iterator())
       {
                Log.d("Errors: ", "$e")
       }
4

1 回答 1

1

您可以使用“NotificationCompat.InboxStyle”这是来自谷歌手册的片段。

var notification = NotificationCompat.Builder(context, CHANNEL_ID)
    .setSmallIcon(R.drawable.new_mail)
    .setContentTitle("5 New mails from " + sender.toString())
    .setContentText(subject)
    .setLargeIcon(aBitmap)
    .setStyle(NotificationCompat.InboxStyle()
            .addLine(messageSnippet1)
            .addLine(messageSnippet2))
    .build()

您可以遍历您的列表并使用 addLine 添加到消息堆栈中。

有关更多信息,请查看此链接

于 2020-05-23T09:19:24.873 回答