通知构建器未能接收完整上下文。

huangapple go评论83阅读模式
英文:

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会使用这些值。

<!-- 设置自定义默认图标。当传入通知消息未设置图标时使用。

&lt;meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/your_image" /&gt;
&lt;!-- 设置传入通知消息的颜色。当传入通知消息未设置颜色时使用。  --&gt;
&lt;meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" /&gt;

阅读关于 设置 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(&quot;YourText&quot;))

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.

&lt;meta-data
    android:name=&quot;com.google.firebase.messaging.default_notification_icon&quot;
    android:resource=&quot;@drawable/your_image&quot; /&gt;
&lt;!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
     notification message.  --&gt;
&lt;meta-data
    android:name=&quot;com.google.firebase.messaging.default_notification_color&quot;
    android:resource=&quot;@color/colorAccent&quot; /&gt;

Read official guideline about Set up a Firebase Cloud Messaging client.

huangapple
  • 本文由 发表于 2020年4月4日 11:50:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/61023542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定