android 在通知中嵌入换行符
我需要在通知中嵌入换行符。我有两行不同的数据,我需要嵌入换行符来区分这两行。 我修改了反斜杠-n,但这不起作用。
有办法做到这一点吗?
I need to embed a newline in a notification. I have two lines of data that are different and I need to embed a newline to distinguish between the two.
I trued a backslash-n, but that does not work.
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管其他人在这里说过,您不需要使用 RemoteViews 或自定义布局来显示多行!
多行文本是可能的,但仅限于展开通知时。
为此,您可以使用 NotificationCompat.BigTextStyle。如果您阅读此处的开发指南,那么您会注意到他们提到了这一点提示:
因此,换句话说:
关于其工作原理需要注意的事项:
如果您不想在推送通知中发送 HTML 格式,那么另一种选择是使用某种 Markdown 格式并在通知之前手动处理它使用 SpannableStringBuilder 进行构建
You do not need to use RemoteViews or a custom layout to show multiple lines, despite what others have said here!
Multiline texts are possible, but only when the notification is expanded.
To do this, you can use NotificationCompat.BigTextStyle. And if you read the dev guides here then you'll notice that they mention this tip:
So, in other words:
Things to note about how this works:
If you don't want to send HTML formatting in your push notification, then another option is to use markdown formatting of some sort and manually handle this before your notification building by using SpannableStringBuilder
据我所知,除了创建自定义
Notification
布局之外,没有其他方法可以做到这一点。Notification
文档提供了执行此操作的分步过程,并且非常全面。 这是指向该内容的链接。创建这两行正如您所需要的,仅意味着在布局 XML 中添加额外的
TextView
。然后,您只需将每个TextView
的文本设置为两行数据,如示例所示。As far as I know there is no way to do this other than creating a custom
Notification
layout. TheNotification
documentation has a step-by-step process on doing this and is quite thorough. Here is the link to that.Creating the two lines as you require would just mean putting in an extra
TextView
in the layout XML. Then you would just set eachTextView
's text to your two lines of data, as the example shows.您需要在您的应用程序中创建自定义通知生成器。更多详细信息请参见:https://developer.android.com/guide /topics/ui/notifiers/notifications.html#CustomExpandedView,我花了很长时间才找到让 firebase 在所有情况下都调用 onMessageReceived 的方法。
基本上,您通过 api 发送给 firebase 的消息在发送给 firebase 服务器的 json 请求中不得包含“notification”键,而只能使用“data”键,如下所示,firebase 服务将调用在上面列出的所有情况下您的 onMessageReceived 。
You need to make custom notification builder in your app. more detail here : https://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView, It takes me so long to find out the way to make firebase to call onMessageReceived in all cases.
basically your message to firebase via api must not have "notification" key in your json request to firebase server and only use "data" key as show below, firebase service will call your onMessageReceived in all cases listed above.