Friday 5 March 2021

Android device doesn't vibrate when calling Vibration.vibrate() in HeadlessJS function

I am successfully using Vibration.vibrate([1000, 2000], true); inside a component in a React Native Android app - the device vibrates when this is called.

However I am also using HeadlessJS to launch a notification when the app is in the background or killed:

App.js:

import backgroundNotificationHandler from './src/services/backgroundNotificationListener';
...

AppRegistry.registerComponent(appName, () => App);
firebase.messaging().setBackgroundMessageHandler(backgroundNotificationHandler);

backgroundNotificationListener.js:

import { NativeModules, Vibration } from 'react-native';
import { parseTimeStringForNotification } from './parseTime'
import InCallManager from 'react-native-incall-manager';

const backgroundNotificationHandler = async message => {

  console.log(Vibration); // logs the Vibration object

  InCallManager.startRingtone('_BUNDLE_'); // this works
  Vibration.vibrate([1000, 2000], true); // this doesn't work
...

Is there any reason this shouldn't work? Is there some kind of OS restriction on this / should I try a third party package here to make the device vibrate?



from Android device doesn't vibrate when calling Vibration.vibrate() in HeadlessJS function

No comments:

Post a Comment