【问题标题】:Firebase FCM notification image won't showFirebase FCM 通知图片不会显示
【发布时间】:2019-12-20 05:08:02
【问题描述】:

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

这里是 firebase 用户界面和应该发生的事情 -

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

这是我的 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);
        }
    }



}



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

【问题讨论】:

    标签: android firebase firebase-cloud-messaging


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-21
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      相关资源
      最近更新 更多