将人添加到NotificationCompat.Builder

时间:2020-09-24 15:19:10

标签: android kotlin androidx

我试图将一个Person添加到NotificationCompat,但是它只包含字符串。 Notification不同。如Android: Using Person with NotificationCompat中所述,应使用AndroidX。现在让我感到困惑的是,NotificationCompat有数据包androidx.core.app,而Notification有数据包android.app。是否有其他接受Person的AndroidX类?预先感谢

val person = Person.Builder()
    .setName("John")
    .build()

NotificationCompat.Builder(context, someId)
    .addPerson(person) // only accepts string
    ...
    .build()

1 个答案:

答案 0 :(得分:0)

根据文档,它也接受Person作为参数:

NotificationCompat.Builder.addPerson(person)如图here

使用compat / androidX库来支持OS实现始终是更好的选择,因为它们具有完全的向后兼容性(如果可能)。

相关问题