Android:将 Person 与 NotificationCompat 结合使用 [英] Android: Using Person with NotificationCompat

查看:67
本文介绍了Android:将 Person 与 NotificationCompat 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 AndroidPerson 类来创建 notification 的发送者,以便用户图像显示在 Android P 中的 MessagingStyle 通知中.

I want to use Android's Person class to create a sender of a notification so the user image is displayed in MessagingStyle notifications in Android P.

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

However, the NotificationCompat.MessagingStyle class doesn't support using the Person class, it only seems to be supported by Notification.MessagingStyle (see the addMessage method).

有没有办法将 Person 类与 NotificationCompat 一起使用?

Is there any way to use the Person class with NotificationCompat?

这就是我想要做的:

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 实现相同的效果?

In case there isn't, I need to use the NotificationCompat.MessagingStyle class because I'm using the method "extractMessagingStyleFromNotification" to keep the existing messages in the notification, that way I only need to add the new one. Is there any way to achieve the same using Notification.MessagingStyle?

推荐答案

解决方案是使用AndroidX 而不是 Android 支持库,因为后者不再更新.

The solution is to use AndroidX instead of Android Support Library, since the latter is no longer updated.

这篇关于Android:将 Person 与 NotificationCompat 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆