2

I'm using the FCM legacy REST API to send notifications to my Android App. I've managed to include a LargeIcon in the notification using the image attribute. My problem is that I don't want my notification to expand, as when it expands it shows this image enlarged, covering the whole expanded notification. When the notification collapses it displays the icon properly to the right.

How can I prevent the notification from expanding when pushing from the REST API (while App is in background).

Here's my notification body:

{
    title: 'Title',
    body: 'Notification Body',
    icon: 'myicon',
    image: 'url_of_image'
};

EDIT: As requested I've added a screenshot of how the notifications look. Also, the Debug Stacktrace shows that the system downloads the image from the given url when the notification is received. enter image description here

Manu Sisko
  • 269
  • 2
  • 17
  • The legacy APi doesn't support the image attribute. Can you show us the URL you are using to send the notification? – Derryl Thomas Mar 02 '20 at 07:11
  • I'm pushing to https://fcm.googleapis.com/fcm/send – Manu Sisko Mar 02 '20 at 19:57
  • That URL is for the legacy API. The new HTTP V1 API will look something like this - https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send – Derryl Thomas Mar 03 '20 at 07:51
  • Refer this document to migrate to the new API - https://firebase.google.com/docs/cloud-messaging/migrate-v1 – Derryl Thomas Mar 03 '20 at 07:52
  • I'm very curious as to how the image is getting rendered for you, considering that the legacy API doesn't have an image parameter as you can see here - https://firebase.google.com/docs/cloud-messaging/http-server-ref. Are you rendering it from your app? – Derryl Thomas Mar 03 '20 at 08:16
  • Great. I'll see fit to migrate. No, I've tested with Data + Notification Messages while App is in the background. I'll post a pic asap, as the image does in fact, go through – Manu Sisko Mar 03 '20 at 13:16
  • Yes! Please do! I'd like to know how that works. Also, if you just setting up push notifications for your app, I'd suggest to do it with the new API instead of the legacy for multiple reasons mentioned in the about FCM documentation – Derryl Thomas Mar 03 '20 at 14:22
  • I've added the screenshot of the notification. Hope this helps! – Manu Sisko Mar 03 '20 at 17:29

1 Answers1

0

You can send a data-only push notification to your device. Send the image URL as part of the data payload.

This will give you control in the onMessageReceived method. Here you can generate and display the notification however you like it. Retrieve the image URL here and download the image and create a notification with the image as the icon or however you want it to be rendered.

Derryl Thomas
  • 1,324
  • 12
  • 22
  • Yes, I've found this approach. May I note, I need to also follow [this](https://stackoverflow.com/a/53082939/9489014) implementation of FCM Service, in order to guarantee that the notification gets through even when the app is killed. – Manu Sisko Mar 05 '20 at 14:50