React-native-push-notification: vibrate: false is ignored

Created on 18 Jul 2019  路  20Comments  路  Source: zo0r/react-native-push-notification

Hi,

my settings disabling to vibrate function, but on each notification my device are still vibrating. It is a bug in your lib or have I a misconfiguration?

"react-native": "^0.58.6"
"react-native-push-notification": "^3.1.3"

test-device: huawai p10 lite
android: 8.0.0

my settings:
`localNotif(message, item) {
PushNotification.localNotification({
/* Android Only Properties */
id: '1',
autoCancel: true,
largeIcon: "ic_launcher",
smallIcon: "ic_notification",
bigText: message,
vibrate: false, // (optional) default: true
vibration: 0, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
itemData: item,

        /* iOS only properties */
        alertAction: 'view', 
        category: null, 
        userInfo: null, 

        /* iOS and Android properties */
        title: Localization('General.Download.DownloadTitle'), // (optional)
        message: message, // (required)
        playSound: false, // (optional) default: true
        soundName: 'default', 
        number: '10', 
        // actions: '["Yes", "No"]',  
    });
}`

Most helpful comment

This is a bug in Android 8+. You can fix it in RNPushNotificationHelper.java.

long vibration = bundle.containsKey("vibration") ? (long) bundle.getDouble("vibration") : DEFAULT_VIBRATION;
        long[] vibratePattern = (bundle.containsKey("vibrate") && bundle.getBoolean("vibrate")) ? new long[]{0, vibration} : new long[]{ 0 };

        channel.setDescription(this.config.getChannelDescription());
        channel.enableLights(true);

        channel.setVibrationPattern(vibratePattern);
        channel.enableVibration(true);

        manager.createNotificationChannel(channel);
        channelCreated = true;

Add this at the end of the file.

All 20 comments

I'm also having this issue. Any update or progress?

This is a bug in Android 8+. You can fix it in RNPushNotificationHelper.java.

long vibration = bundle.containsKey("vibration") ? (long) bundle.getDouble("vibration") : DEFAULT_VIBRATION;
        long[] vibratePattern = (bundle.containsKey("vibrate") && bundle.getBoolean("vibrate")) ? new long[]{0, vibration} : new long[]{ 0 };

        channel.setDescription(this.config.getChannelDescription());
        channel.enableLights(true);

        channel.setVibrationPattern(vibratePattern);
        channel.enableVibration(true);

        manager.createNotificationChannel(channel);
        channelCreated = true;

Add this at the end of the file.

Any chances we can get a few fixes pushed into the library?

@necto68 Do you have the links on docs about that android bug? github issue, docs, or anything.
That code solution didn't work for me

@necto68 tnx, this solution works on my Google Pixel (Android 10).

If someone can't get this solution to work, make sure to clear the app data or reinstall the app after you update the RNPushNotificationHelper.java - if I understand correctly, changes to vibration pattern (or any changes related to notification channels) require clean start.

This is a bug in Android 8+. You can fix it in RNPushNotificationHelper.java.

long vibration = bundle.containsKey("vibration") ? (long) bundle.getDouble("vibration") : DEFAULT_VIBRATION;
        long[] vibratePattern = (bundle.containsKey("vibrate") && bundle.getBoolean("vibrate")) ? new long[]{0, vibration} : new long[]{ 0 };

        channel.setDescription(this.config.getChannelDescription());
        channel.enableLights(true);

        channel.setVibrationPattern(vibratePattern);
        channel.enableVibration(true);

        manager.createNotificationChannel(channel);
        channelCreated = true;

Add this at the end of the file.
@necto68 Can you show me your RNPushNotificationHelper.java?
Thank you!

Hi!
A PR is welcome, I will take a look ASAP!

Any updates on pushing a fix for the library? I'm having this issue with my app as well.

Hi @maxtotallycodes
I will take a look to this issue ASAP.
Since I don't have a Android phone available currently to test, a PR is welcome !

Hey @Dallas62, it sounds like @necto68 has the fix above (https://github.com/zo0r/react-native-push-notification/issues/1140#issuecomment-528331545). Unfortunately I'm not technical (the username is a bit tongue in cheek), but I'm investigating because my team is having this issue.

I check this fix but it's not so easy...
When the channel is created, you can not update it anymore. So if we apply this settings once, you will have the same behaviour for all notifications. To get remote notification you need a default channel, which is a problem this there is no easy way to manage channel with the library.
I think we should refactor the library to implement a complement management of channels, it will be exclusive to Android but might answer to all those problems.

How much work would a refactor like that be? My team (and I'm sure many others) would be okay with a clunkier solution in the short term that requires some work on our end because right now we're buzzing all our users phones when we really shouldn't be and driving them nuts. Even if it's not a perfect solution, anything would be great!

Hi @maxkomarychev
I will try to start this part tomorrow if there is not too many issues open this night 馃ぃ

Thank you! 馃檹 We'll cross our fingers!

Hi @maxtotallycodes a new release is available with a fix on vibrate.
I took a look on the work for Android Channel, and wix/react-native-notifications seems to handle it, but they don't have scheduled notification. I think it's better to work with them to implement scheduled notifications, than refactor this library.

We tried out the new release and unfortunately it made all our notifications the silent kind that appear minimized at the bottom of the notification tray (and they're only visible when you open the notification tray). :(

If working with that other library is the best option, do we have code they could use for scheduled notifications?

We tried out the new release and unfortunately it made all our notifications the silent kind that appear minimized at the bottom of the notification tray (and they're only visible when you open the notification tray). :(

If working with that other library is the best option, do we have code they could use for scheduled notifications?

Sorry for this issue, I fixed it on 3.3.1.

@Dallas62 that seemed to do the trick, thank you!

Hello,

After upgrading to 3.3.1 from 3.2.1, I'm getting "Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context) first."

I am not using remote notifications nor firebase, why am I getting this?

Hi @clintonjrobinson
This issue has already been answered and README.md is up to date.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atteia picture atteia  路  4Comments

sungjinoh picture sungjinoh  路  3Comments

DanDance picture DanDance  路  3Comments

cookienawer picture cookienawer  路  3Comments

ahmadallo1 picture ahmadallo1  路  3Comments