Search code examples
androidfirebase-cloud-messagingandroid-notificationsfirebase-notifications

Android: How do I find Id/modify/dismiss a notification from FCM loud push


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


Solution

  • 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