android - Firebase FCM 通知图片不会显示

标签 android firebase firebase-cloud-messaging

我在我的项目中使用 FCM,在尝试使用 firebase 的“撰写通知”功能测试传入通知时,我在消息中添加了标题、正文和图像 URL,它显示了消息的外观 -带有图像的丰富通知。但是发送给我的通知是一个没有任何图像的正常通知。

这是 firebase UI 以及应该发生的事情 -

enter image description here

我的问题是我只得到文本,没有图像。

这是我的 MyFirebaseMessagingService 类 -


public class MyFirebaseMessagingService extends FirebaseMessagingService {

    public static final String RECEIVED_FCM_ACTION = "com.onemdtalent.app.RECEIVED_FCM_ACTION";

    public static final String BD_KEY_BODY = "BD_KEY_BODY";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // [START_EXCLUDE]
        // There are two types of messages data messages and notification messages. Data messages are handled
        // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
        // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
        // is in the foreground. When the app is in the background an automatically generated notification is displayed.
        // When the user taps on the notification they are returned to the app. Messages containing both notification
        // and data payloads are treated as notification messages. The Firebase console always sends notification
        // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
        // [END_EXCLUDE]

        String image = remoteMessage.getData().get("image");

        Timber.d("onMessageReceived: %s", remoteMessage.getFrom());
        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {

            String body = remoteMessage.getNotification().getBody();
            Timber.d("Message Notification Body: %s", body);



            // broadcast
            Intent localIntent = new Intent(RECEIVED_FCM_ACTION);
            localIntent.putExtra(BD_KEY_BODY, image);
            LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
        }
    }



}



正如我所说,我只得到没有图像的文本。我错过了什么?

最佳答案

已解决 - 我使用了旧版本的 firebase 消息传递依赖项并更新了它,包括我的整个项目到 androidX,现在我可以看到图像 :)

关于android - Firebase FCM 通知图片不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57481191/

相关文章:

android - 底部栏导航未显示所有标题

javascript - Firebase 参数太多。运行 firebase 帮助模拟器 :start for usage instructions

ssl - Windows XP/server 2003 的 Nest API 问题

android - 当应用程序处于后台时,FCM 推送通知显示白色方形图标而不是应用程序图标

ios - 具有 Firebase 消息传递和 Firebase 动态链接的 Cordova Ionic 项目

android - 在 Android Nougat 7.+ 版本中检测当前正在运行的应用程序

java - 如何在 firebase 中获取所有 child 的数据并将其显示到我的 Android 应用程序中?

不同Android ID的Android布局

firebase - 在 Firebase 中安排作业

javascript - 如何避免向 Firebase 的 'Miscellaneous' channel 发送通知?