【问题标题】:Constructor of `NotificationCompat.MessagingStyle(String userDisplayName)` is deprecated`NotificationCompat.MessagingStyle(String userDisplayName)` 的构造函数已弃用
【发布时间】:2021-02-14 18:55:01
【问题描述】:

我想为我的聊天通知构建器使用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)
    }



【问题讨论】:

    标签: android android-studio kotlin push-notification android-notifications


    【解决方案1】:

    详情请查看: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)
    

    【讨论】:

      猜你喜欢
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 2013-10-28
      • 2021-09-10
      • 2017-12-04
      • 1970-01-01
      • 2011-11-07
      相关资源
      最近更新 更多