Firebase FCM notification image won't show

你说的曾经没有我的故事 提交于 2020-01-25 04:22:30

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/57481191/firebase-fcm-notification-image-wont-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!