2

If fcm message contains "notification" section and app is in the background, Notifications delivered to the system tray and data in extras of the intent.

The problem is that I cannot change Importance for this notifications and they always do not show the popup. I fixes this problem for api 26+, i added Notification channel with

int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel channel = new NotificationChannel(getString(R.string.default_notification_channel_id), name, importance);

and in the manifest

<meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id"/>

But for the api 25- i cannot find the solutions. The one suggestions are to remove "notification" section and leave only "data", this will allow fcm deliver messages to

onMessageReceived(RemoteMessage remoteMessage)

when app is in background/foreground and I will be able to show my custom notifications.

Yuri Popiv
  • 519
  • 4
  • 15
  • Do you want to change an importance of the notification which is delivered when your app is in the background? – wonsuc Jun 01 '18 at 12:56
  • @wonsuc yes, because they are showing without pop-up. – Yuri Popiv Jun 01 '18 at 13:02
  • How about the way sending with only `Data` payload? Is that way not applicable for you? – wonsuc Jun 01 '18 at 13:05
  • @wonsuc yes, i thought about this. But i cannot understand why fcm allows you in manifest change default notification icon/color/notification channel but doesn't allow to change importance. – Yuri Popiv Jun 01 '18 at 13:08
  • If you really need to send with `Notification` payload, there is option name with `priority` which functionally same with `Importance`. But when the payload is `Notification` type, default `priority` option is "high". Try to put `priority` option as "high". Detail documentation is [here](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json). – wonsuc Jun 01 '18 at 13:15
  • @wonsuc i tried. Priority and Importance are not the same. – Yuri Popiv Jun 01 '18 at 13:19
  • Yeah. it's diffrent but functionally same. Please read the [documentation](https://developer.android.com/training/notify-user/build-notification#builder) – wonsuc Jun 01 '18 at 13:24
  • One more thing: Try to long press your notification and click the `MORE SETTINGS` and it will show the `Channels` which your created. Click the one of channel and now you can see the importance of the channel. Check if the importance is `high` or `urgent`. – wonsuc Jun 01 '18 at 13:28
  • I'm not sure if your issue is only for below of Android O. – wonsuc Jun 01 '18 at 13:29
  • @wonsuc importance is "Urgent" because i have created channel with `NotificationManager.IMPORTANCE_HIGH` and set this channle to `com.google.firebase.messaging.default_notification_channel_id`. But there is no ways to do the same for 25 and lower. – Yuri Popiv Jun 01 '18 at 13:38
  • This is a quite strange behavior. On 25 and lower, it uses `Priority` instead of `Importance`. If you set `priority` option as "high" when you send FCM, it definitely shows like pop up. You can check related [answers](https://stackoverflow.com/questions/12758681/android-how-can-i-put-my-notification-on-top-of-notification-area). Now what you can try is 1: Sending only with Firebase Console with Priority `High`. 2: Sending only Notification payload (without Data values). Try both and let me know the result. – wonsuc Jun 01 '18 at 13:50
  • Sometimes, it works correctly if you reboot the device or try diffrent device. – wonsuc Jun 01 '18 at 13:51

1 Answers1

1

The best solution i have found is to use only Data payload and handle both background/foreground messages inside onMessageReceivedmethod and show your custom notifications.

Yuri Popiv
  • 519
  • 4
  • 15
  • Hi, can you please put data payload json? what exactly you are sending? because I tried with data payload. but notification not received when app is in background. – Sagar Maiyad Feb 05 '22 at 09:56