'How to make notifications vibrate phone react native expo

I need notifications to vibrate the phone repeatedly until the user performs an action like clicking on the notification. I have found no way to make this work yet. At first, I sought to solve it using the Vibrate Api from react native expo. But I later came to realize that the expo cannot react to notifications if app is killed and user did not interact with the notification as stated here. The only other way is to give the notification a setting to vibrate and the interval. But I can't seem to find a way to do that. I am using node js to send the notification, which is practically the same code as this. This are the only formats used to send a message. There is no vibrate. But on the initial page, I see them adding vibrate. I must be mistaken somewhere or lost. I suppose this can be done somehow, else there wouldn't be alarm apps. How can I do this? On my android phone, the notification doesn't even vibrate at all and The app would be useless if I do not have this feature. Thank you ):



Solution 1:[1]

I later found the answer to this. On andriod, you must create a channel and include it when sending the notifications. All explanation in the docs. You would be able to create a vibration pattern and so forth. Also if your like me who did the sending of notification in the backend (I used nodejs), you can still create a channel but it has to be on the frontend. Use this code in a useEffect:

if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
  name: 'default',
  importance: Notifications.AndroidImportance.MAX,
  vibrationPattern: [0, 250, 250, 250],
  lightColor: '#FF231F7C',
});

}

You can replace 'default' with whatever name you want to call the notification channel. I haven't yet found out how to do this on ios. If I do, I will update. Hopefully I don't forget ):

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NewUser134