`NotificationCompat.MessagingStyle(String userDisplayName)` 的构造函数已弃用

Constructor of `NotificationCompat.MessagingStyle(String userDisplayName)` is deprecated

我想为我的聊天通知生成器使用 MessagingStyle,但我只有发件人的用户名,我阅读了文档,发现我可以使用 MessagingStyle(Person person) 构造函数。

如何用 Person 实例化 MessagingStyle?

val notificationBuilder: NotificationCompat.Builder =
    NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID).apply {
        setShowWhen(false) 
        
        // Set the Notification style
        // setStyle(NotificationCompat.MessagingStyle(Person)) ??
        
        color = Color.WHITE
        setSmallIcon(R.drawable.chat_notif_small_icon)
        setOnlyAlertOnce(true)
        setContentIntent(contentPendingIntent)
        setOngoing(false)
    }



有关详细信息,请查看:https://medium.com/google-developer-experts/exploring-android-p-enhanced-notifications-a9adb8d78387

val sender = Person.Builder()
        .setName(R.string.user_name)
        .build()

然后用这个作为

NotificationCompat.MessagingStyle(sender)
        .addMessage("Check this out!", Date().time, sender)
        .setBuilder(notificationBuilder)