0

我想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)
    }



4

1 回答 1

2

有关详细信息,请查看: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)
于 2021-02-14T23:54:02.340 回答