首页 > 解决方案 > Android:使用带有 NotificationCompat 的 Person

问题描述

我想使用Android'sPerson类来创建 a 的发送者,notification以便用户图像显示MessagingStyleAndroid P.

但是,NotificationCompat.MessagingStyle该类不支持使用Person该类,它似乎仅受支持Notification.MessagingStyle(参见 addMessage 方法)。

有什么方法可以使用这个PersonNotificationCompat吗?

这就是我想要做的:

NotificationCompat.MessagingStyle msgStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(notification); 

Person.Builder builder = new Person.Builder().setName(name).setIcon(icon);

msgStyle.addMessage(message, System.currentTimeMillis(), builder.build());

如果没有,我需要使用NotificationCompat.MessagingStyle该类,因为我使用“extractMessagingStyleFromNotification”方法将现有消息保留在通知中,这样我只需要添加新消息。有什么方法可以实现相同的使用Notification.MessagingStyle

标签: javaandroidnotificationsandroid-push-notification

解决方案


解决方案是使用AndroidX而不是 Android Support Library,因为后者不再更新。


推荐阅读