2

We're trying to migrate from silent FCM pushes to loud ones (i.e. from "data":{} managed by the app, to those that "notification": {} causes). With loud push, FCM client framework automatically creates a notification. Therefore:

  • I don't have its ID so I can modify it
  • I can't control its channel ID (which is important starting Oreo).
  • Not sure if there is a way for my server to request a specific notification sound for it (the same way they do in iOS). Actually, I can do that from onRemoteMessage() but the auto generated notification plays the default beep, which will cause a funny playing of both sounds.

How can I solve those issues?

Thanks

Maneki Neko
  • 1,177
  • 1
  • 14
  • 24

1 Answers1

1

In case of notification payload when FCM client framework automatically creates a notification using notification payload data. Notification payload contains a key for sound so you have to set it from server side.

For Example :

{
    "to" : "yourToken",

    "notification" : {
      "body" : "Notification Body",
      "title" : "Notification Title",
      "sound" : "/res/raw/yourSoundResourceFile"
    }
  }   

As per as firebase documentation sound is a Optional string

Supports "default" or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/.

For more info follow this offical firebase link

Mayank Sharma
  • 2,735
  • 21
  • 26
  • Hi. Thanks. But what about the notification ID (to cancel/modify)? And - is there a built in way to say "Don't play a tone"? Or is the best practice "silence.mp3" that contains silence? – Maneki Neko Dec 26 '18 at 06:07
  • 1
    As they are directly show to notification tray so you can not cancel or modify the notification (in case of notification payload). Notification shows automatically and on click of that Default Activity open ( Where you can get data in data payload by bundle ) and notification hide automatically. So if you need any data on click of notification which are generated through notification payload simply get it from bundle of your activity. – Mayank Sharma Dec 26 '18 at 06:11
  • 1
    for more info handle a notification payload click on following SO link https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase – Mayank Sharma Dec 26 '18 at 06:14
  • Hi. Thanks. Noticed that but - Think of a message you get in WhatsApp, but you open the app from the launcher (not from the notification) and view the conversation. In that case, you'd like to vanish that notification (done in client side). Another scenario: Same WhatsApp message - but before you open it - the sender cancels it. The message is no longer relevant so - if the notification stays, the user would open it - just to discover that there's nothing to see (can be done on client side on Android (not in iOS), but would be nice if the server could also do that). – Maneki Neko Dec 26 '18 at 06:54
  • Oh, and I notice something in silent messages, it's called something like "Notification-ID" or so, in the JSON that wraps the payload. On silent messages it's something like "0000-0000-0000" or so. Maybe it's that thing can do the magic? – Maneki Neko Dec 26 '18 at 06:58
  • Yes, I hope I nailed it this time! Part of it, at least... [getNotification](https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage.Notification) is where you get all the fields. One is "tag". Will make experiments to see. – Maneki Neko Dec 26 '18 at 07:08