I’m using the Expo Pedometer:(https://docs.expo.io/versions/latest/sdk/pedometer/), and have a working step-counter which works well on one page of my app.
It counts up as expected as I walk when i hold my phone with the screen open, using state to store the currentSteps. However, when I turn my phone screen off/lock my phone, the steps do not go up as I walk - it only works if i have the screen open.
I have been reading about Expo Task Manager: https://docs.expo.io/versions/latest/sdk/task-manager/ but really have not much of an idea how I should even go about this…
If you would like to see my current code I am happy to provide it but it is essentially the example code from the expo pedometer docs.
My goal is to have the pedometer count the user’s steps no matter if the app is open or not; so when the user checks the app, they can see their daily steps from within the app in real time.
Are you using
Pedometer.watchStepCount()? Do you get any different results if you use
Pedometer.getStepCountAsync()? Seems like the former is more like “here are the steps that are coming in while I am watching” (and it’s not watching while the app is closed), while the latter is “here are the total steps from these services on the phone that are always running in the background.” If you just need to periodically update how many steps a user has taken, just using the latter might be fine, while you may need to combine the two in order to show an accurate total that also increments live when the app is open.
Thanks for your response.
When I am testing your suggestion using
Pedometer.getStepCountAsync() I get the error :
“Getting step count for date range is not supported on Android yet.”
This is again just using the basic recommended code from Expo Pedometer Docs
I have a small hope that this may be an issue with the Android OAuth note that is mentioned in the bottom of the docs. I will explore this and get back to you here.
As a follow-up, I have enabled the Fitness API in my Google Developer Console but still, have no luck.
I’ve raised a Stack Overflow thread here if this provides any more context.
I am a bit stuck here - any advice on what else to try would be awesome.
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.