英文:
Notification Builder not receiving full context
问题
我正在使用以下代码配置通知构建器,在安卓设备上通过 Firebase 云函数接收通知。我成功地接收到通知。但是通知的内容在图像中显示不完整。
在左上方,图标显示为灰色,未显示实际图标,并且文本未完全显示。
我应该如何纠正上述问题?
通知构建器
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, ADMIN_CHANNEL_ID)
.setSmallIcon(R.drawable.finalicon)
.setLargeIcon(largeIcon)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(notificationSoundUri)
.setContentIntent(pendingIntent);
英文:
I am using below code for notification builder for receiving notification on android device from through firebase cloud function. I am receiving notification successfully. but The context of the notification is not completely visible as you can see in the image.
On the top left icon is displayed as grey and not showing the actual icon and the text is not shown completely.
How should I rectify the above issues?
Notification Builder
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, ADMIN_CHANNEL_ID)
.setSmallIcon(R.drawable.finalicon)
.setLargeIcon(largeIcon)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(notificationSoundUri)
.setContentIntent(pendingIntent);
答案1
得分: 1
我建议您阅读 NotificationCompat.BigTextStyle
。
> 用于生成包含大量文本的大格式通知的辅助类。如果平台不提供大格式通知,则此方法无效。用户将始终看到普通通知视图。
.setStyle(new NotificationCompat.BigTextStyle().bigText("YourText"))
应用 NotificationCompat.BigTextStyle
以在通知的扩展内容区域中显示文本。请查阅关于 添加大块文本 的官方指南。
FYI
当传入的消息未显式设置图标或颜色时,Android会使用这些值。
<!-- 设置自定义默认图标。当传入通知消息未设置图标时使用。
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/your_image" />
<!-- 设置传入通知消息的颜色。当传入通知消息未设置颜色时使用。 -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
阅读关于 设置 Firebase 云消息传递客户端 的官方指南。
英文:
I would kindly suggest you to read NotificationCompat.BigTextStyle
.
> Helper class for generating large-format notifications that include a
> lot of text. If the platform does not provide large-format
> notifications, this method has no effect. The user will always see the
> normal notification view.
.setStyle(new NotificationCompat.BigTextStyle().bigText("YourText"))
Apply NotificationCompat.BigTextStyle
to display text in the expanded content area of the notification. Kindly visit official guide line about Add a large block of text.
FYI
Android uses these values whenever incoming messages do not explicitly set icon or color.
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/your_image" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
Read official guideline about Set up a Firebase Cloud Messaging client.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论