简体   繁体   English

是否可以在带有可扩展选项的推送通知中发送 Firebase(FCM) 通知消息(多行消息); 使用 Python?

[英]Is it possible to send Firebase(FCM) notification message(multiple lined message) in the push notification with expandable option on it; using Python?

I searched for the solution but could not find any relevant results.我搜索了解决方案,但找不到任何相关结果。

This is what i am trying but didn't get desired output -这就是我正在尝试但没有得到想要的输出 -

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)

Ok, Straight forward, In below attached image you can see green squared expand option for WhatsApp and Gmail chat notification.好的,直截了当,在下面的附图中,您可以看到WhatsAppGmail chat通知的green方形展开选项。 I want the same for my red squared notification that i sent using firebase FCM.我希望我使用 firebase FCM 发送的red方块通知也一样。

If it's not possible using FCM then how we can achieve this??如果不可能使用 FCM 那么我们如何实现这一目标?

在此处输入图像描述 Thank you!谢谢!

This will depend on how the notification is being handled in the client.这将取决于通知在客户端中的处理方式。 For example, look into the sendNotification method from the Firebase Messaging sample :例如,查看 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)

Here the notification is being generated, and as suggested in this answer , setting the style in the notification with setStyle will result in the behavior your are expecting:此处正在生成通知,正如此答案中所建议的那样,使用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))

This is the result I got:这是我得到的结果:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM