【问题标题】:Notification Builder not receiving full context通知生成器没有收到完整的上下文
【发布时间】:2023-03-04 07:59:07
【问题描述】:

我正在使用以下代码用于通知生成器,以便通过 firebase 云功能在 android 设备上接收通知。我正在成功收到通知。但是通知的上下文并不像您在图像中看到的那样完全可见。

左上角图标显示为灰色,不显示实际图标,文本未完全显示。

我应该如何纠正以上问题?

通知生成器

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);

【问题讨论】:

    标签: java android firebase firebase-cloud-messaging android-notifications


    【解决方案1】:

    我建议您阅读NotificationCompat.BigTextStyle

    用于生成包含 很多文字。如果平台不提供大幅面 通知,此方法无效。用户将始终看到 正常的通知视图。

     .setStyle(new NotificationCompat.BigTextStyle().bigText("YourText"))
    

    应用 NotificationCompat.BigTextStyle 在通知的扩展内容区域中显示文本。请访问有关Add a large block of text的官方指南。

    仅供参考

    只要传入的消息没有明确设置图标或颜色,Android 就会使用这些值。

    <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" />
    

    阅读有关Set up a Firebase Cloud Messaging client的官方指南。

    【讨论】:

    • 先生,请再次阅读问题,我无法完全显示文本,也无法显示实际图标图像,您可以看到我已经分享的屏幕截图。请协助我。非常感谢您的努力。
    猜你喜欢
    • 2012-01-08
    • 2014-06-21
    • 2017-09-18
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 2013-12-24
    相关资源
    最近更新 更多