Firebase FCM通知图像不会显示 [英] Firebase FCM notification image won't show

查看:167
本文介绍了Firebase FCM通知图像不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用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);
        }
    }



}



正如我所说,我只得到文本而没有图像.我想念什么?

解决方案

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

I am using FCM in my project and when trying to test the incoming notifications with the firebase "compose notification" feature I am putting a title, a body and an image URL to the message and it shows what it should look like - a rich notification with image. But the notification that is being sent to me is a normal one without any image.

here is the firebase UI and what is suposed to happen -

My issue is that I am getting only the text, without the image.

here is my MyFirebaseMessagingService class -


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



}



As I sayed, I am getting only the text without the image. what am I missing?

解决方案

Solved - I used an old version of firebase messaging dependency and I updated it, including my entire project to androidX and now I can see the images :)

这篇关于Firebase FCM通知图像不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆