React-native-firebase: Device doesn't vibrate on receiving notification and heads up notification- android

Created on 8 Jan 2018  路  15Comments  路  Source: invertase/react-native-firebase

I was just trying the plugin for a new project as a POC.
I could integrate easily with all the documentation and it works well on an android device(hasn't tested yet for iOS).

I am receiving notification when the app is in background and I am notification sound works when i enable sound parameter in firebase console. But no matter what I do, the device doesn't vibrate.

I tried setting "vibrate" parameter to true in the notification payload too. It doesn't work.

Also, I am looking for a way to show a heads-up notification on android. Setting the priority to high in the payload works on iOS but it doesn't seem to work on android.

(had all the same issues with another plugin, so trying this out)

Messaging

Most helpful comment

This works for me
.android.setVibrate([1000, 1000]) .android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])

All 15 comments

@skasanibanyan FCM support is a little shaky at the moment and we're planning on overhauling it in our next major release. We've had lots of similar issues reported that we're closing off until we properly fix the functionality.

Keep track of this for updates: https://github.com/invertase/react-native-firebase/issues/595

any updates on this?

Hi, I have the same issue too. I have set vibration in js, add permission in android manifest xml but only sound played, vibration not working at all.
Any updates?

Same problem here.

For me setting the setVibrationPattern on the channel is working.

const channel = new firebase.notifications.Android.Channel('all-notifications', 'All Notifications', firebase.notifications.Android.Importance.Max) .setVibrationPattern([500]) .setDescription('All Notifications');

For me setting the setVibrationPattern on the channel is working.

const channel = new firebase.notifications.Android.Channel('all-notifications', 'All Notifications', firebase.notifications.Android.Importance.Max) .setVibrationPattern([500]) .setDescription('All Notifications');

it is not working i have set in the constructor of the component

Did you set the channelId on the notification?

const notification = new firebase.notifications.Notification()
.setNotificationId(id)
.setTitle(title)
.android.setChannelId(channel.channelId)
firebase.notifications().displayNotification(notification);

Also, make sure you update the manifest https://github.com/invertase/react-native-firebase-docs/blob/master/docs/notifications/android.md

the notification constructor applies only for notifications received in foreground, because you are responsible to show it. But in background we can't handle the notification so the only way to set vibration is in some kind of initial config like channel creation, android manifest or the notification payload itself.

in my case i can make sound and vibrate for notifications that i show in foreground, but i can't figure it out how to make vibration works with background notifications

im doing this

const channel = new firebase.notifications.Android.Channel(FIREBASE.ANDROID_CHANNEL, 'MyApp', firebase.notifications.Android.Importance.Max)
        .enableVibration(true) // doesn't work
        .setVibrationPattern([400, 400]) // doesn't work
        .setDescription('Canal para las notificaciones');
      firebase.notifications().android.createChannel(channel);

the sound works fine because i set sound: 'default' in the notification payload

@dengue8830 I have sound and vibration setup but I noticed the vibration only works with my android set to vibrate mode. If I change my phone to sound mode, it doesn't vibrate, only sound. Not sure if that is your issue.

yes, that's my case...it could be the default behavior of firebase? rn-firebase?

the only way to solve this could be create my own java class to handle the background notifications :stuck_out_tongue_closed_eyes:

This works for me
.android.setVibrate([1000, 1000]) .android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])

.android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])

is this for FOREGROUND right ?? how about background to vibrate + sound

.android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])

is this for FOREGROUND right ?? how about background to vibrate + sound

Yes, it works in the background for Android. So I create a file named by backgroundPush.js with path "src/backgroundPush.js". This is the code

import firebase from 'react-native-firebase';

export default async (message) => {
    try {
        const text = message.data.message;
        const payload = JSON.parse(message.data.sendbird);
        const localNotification = new firebase.notifications.Notification({
            show_in_foreground: true,
            sound: 'default'
        })
            .android.setChannelId('com.alinamed.app.default_channel_id')
            .android.setVibrate([1000, 1000])
            .android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])
            .android.setPriority(firebase.notifications.Android.Priority.High)
            .android.setSmallIcon('ic_launcher')
            .android.setVibrate(1000)
            .setNotificationId(message.messageId)
            .setTitle(payload.sender.name)
            .setSubtitle(`Belum dibaca: ${payload.unread_message_count}`)
            .setBody(text)
            .setData(payload)
            .setSound('default');
        return firebase.notifications().displayNotification(localNotification);
    } catch (e) {
        return Promise.resolve();
    }
}

Then I register it in index.js

import backgroundPush from './src/backgroundPush';
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => backgroundPush);

Don't forget to set the react native firebase boilerplate before.

This works for me
.android.setVibrate([1000, 1000]) .android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])

where this code is added

Was this page helpful?
0 / 5 - 0 ratings