It is possiblle to use Pedometer in Background or when the app is closed in expo ?

  1. SDK Version: 44
  2. Android
  3. expo-sensors (Pedometer)

I am trying to count user steps in background using TaskManager and BackgroundFetch.
I use Pedometer.watchStepCount() functions

example code:

TaskManager.defineTask(PEDOMETER_TASK_NAME, async ({ data, error }) => {
if (error) {
return;
}

Pedometer.watchStepCount((data) => {
AsyncStorage.setItem(“steps”, JSON.stringify(data.steps));
});
});

async function registerBackgroundPedometerFetchAsync() {
return BackgroundFetch.registerTaskAsync(PEDOMETER_TASK_NAME, {
minimumInterval: 1,
stopOnTerminate: false, // android only,
startOnBoot: true, // android only
});
}

this solution doesn’t work, I was trying to use Pedometer.watchStepCount() in combination with
Location.startLocationUpdatesAsync() but there was no effect.
Is it possible to do it in expo ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.