[英]Is it possible to send Firebase(FCM) notification message(multiple lined message) in the push notification with expandable option on it; using Python?
我搜索了解决方案,但找不到任何相关结果。
这就是我正在尝试但没有得到想要的输出 -
message = messaging.MulticastMessage(
notification=messaging.Notification(
title="Title",
body="body line1\nbody line2\nbody line3\nbody line4\nbody line5\nbody line6"),
tokens=['eg-token1','eg-token2','eg-token3',...,'eg-tokenN']
)
messaging.send_multicast(message)
好的,直截了当,在下面的附图中,您可以看到WhatsApp
和Gmail chat
通知的green
方形展开选项。 我希望我使用 firebase FCM 发送的red
方块通知也一样。
如果不可能使用 FCM 那么我们如何实现这一目标?
这将取决于通知在客户端中的处理方式。 例如,查看 Firebase Messaging 示例中的sendNotification
方法:
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle(getString(R.string.fcm_message))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
此处正在生成通知,正如此答案中所建议的那样,使用setStyle
在通知中设置样式将导致您期望的行为:
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle(getString(R.string.fcm_message))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setStyle(NotificationCompat.BigTextStyle().bigText(messageBody))
这是我得到的结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.