Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct code for notification sound in FCM not clear. #560

Closed
eeerrrttty opened this issue Nov 24, 2020 · 2 comments
Closed

Correct code for notification sound in FCM not clear. #560

eeerrrttty opened this issue Nov 24, 2020 · 2 comments

Comments

@eeerrrttty
Copy link

      let message = {
        // notification: {
        //   title: 'Chamada de serviço',
        //   body: `R$ ${(snap.after.data().workDoing.priceCents / 100)}`
        // },
        data : {
          priority: '2',
          messageType: 'data',
          android_channel_id: 'fcm_divas_channel',
          notification_android_channel_id: 'fcm_divas_channel',
          title : 'Chamada de serviço',
          body: `R$ ${(snap.after.data().workDoing.priceCents / 100)}`,
          sound: 'divas',
          notification_title: 'Chamada de serviço',
          notification_body: `R$ ${(snap.after.data().workDoing.priceCents / 100)}`,
          notification_android_sound: 'divas',
          notification_android_priority: '2',
          notification_android_visibility: '1',
          notification_android_vibrate: '8000, 200',
          vibrate: '8000, 200',
          visibility: '1',
          notification_foreground: 'true',
          show_notification: 'true'
        },
        android: {
          collapse_key: 'a',
          priority: 'high',
          ttl: '3600s',
          notification: {
            channel_id: 'fcm_divas_channel',
            sound: 'divas',
            priority:'high'
          }
        },
        // data : {
        //   notification_android_sound: 'divas_sound'
        // },
        // data: {
        //   message: '',
        //   type: 'Call'
        // },
        token: snap.after.data().fcmToken
      }

My code:

            let channel = {
              id: 'fcm_divas_channel',
              sound: 'divas',
              vibration: [8000, 200],
              visibility: 1
            }
            window.FirebasePlugin.createChannel(channel,
              function () {
                console.log('Channel created: ' + channel.id)
              },
              function (error) {
                console.log('Set default channel error: ' + error)
              })

Why my custom sounds doesn't come to users ? I putted the correct sound divas.mp3 on my res/raw with config.xml parameters as documentation

@grumpygary
Copy link

FWIW, apparently the channel_id must be unique for each sound, whether or not you delete the channel before calling createChannel(). Apparently Firebase maintains all previously defined channel_id's, and any attempt to change the sound for an existing id is simply ignored.

NOTE: I found this by adding the sound to what listChannels() returns (it was previously returning only id & name). Once I realized that I couldn't update a sound I made sure that my channel IDs were a hash of the underlying settings in order to avoid this in the future. Things worked much better after that.

dpa99c added a commit that referenced this issue Mar 30, 2021
@dpa99c
Copy link
Owner

dpa99c commented Mar 30, 2021

@eeerrrttty Please build and run the example project to verify that custom sounds are working and as a reference for how to implement in your own project.

@grumpygary Thanks for clarifying this - it's not clear from the Firebase SDK documentation.
I've added a note to the plugin documentation for createChannel().

@dpa99c dpa99c closed this as completed Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants