genericUser
genericUser

Reputation: 7148

FCM flutter enable notification vibration

I'm developing a Flutter application for Android and IOS. I have created notification channels for Android according to this article.

My node.js payload:

const payload = {
      notification: {
        title: "title",
      },
      android: {
        priority: "high",
        ttl: 60 * 60 * 1,
        notification: {
          channel_id: 'YO',
        },
      },
      apns: {
        payload: {
          aps: {
            sound: "sound_03.caf"
          }
        },
        headers: {
          "apns-collapse-id": "yo",
          "apns-priority": "10"
        }
      },
      priority: 10
    }

My notifications are working just fine, for both Android and IOS using. The problem is that vibration is disabled by default.

How to enable notification vibration for Android and IOS for Firebase Cloud Messaging?

Upvotes: 3

Views: 2933

Answers (2)

Kyle Venn
Kyle Venn

Reputation: 8038

For me, I only needed to add it to the notification portion of the message payload.

Below is how it looks in Typescript (but the message JSON is all that matters).

let tokens = ...
let message = {
    message: {
        notification: {
            title: title,
            body: body,
            sound: 'default', // <----- All I needed
        },
        data: {
            ...
        },
    }
}

firebase.messaging().sendToDevice(tokens, message)

Upvotes: 0

Victor Eronmosele
Victor Eronmosele

Reputation: 7706

You can set the sound property to default so it makes uses the default sound if sound is enabled and it vibrates if the device is on vibrate.

You can update your payload to this:

const payload = {
  notification: {
    title: "title",
    sound: "default"
  },
  android: {
    priority: "high",
    ttl: 60 * 60 * 1,
    notification: {
      channel_id: 'YO',
    },
  },
  apns: {
    payload: {
      aps: {
        sound: "default"
      }
    },
    headers: {
      "apns-collapse-id": "yo",
      "apns-priority": "10"
    }
  },
  priority: 10
}

Upvotes: 2

Related Questions