问题
So I'm writing a fitness application for android. I'm using the Google fit API to count the steps. I'm using the Recording API to count the steps when the app is in the background. Once the app is in the foreground I'm fetching the steps count with the History API to show it on the screen. What happens is that the count is not correct. There is a delay until you get the correct and updated count. To be more specific no data is being lost. I guess that the Recording API is updating with a specific time interval.
I'm also using the Sensors API to show the real count on my Activity when it is running. So what happens is that for example you see 300 steps in your screen (real time data). Close the app, open it again and then for the next minute you see 250 steps for example. And only after some time the History API catches the correct data and shows 300 again.
Has anyone found a way through this issue?
Thank you and sorry for the long text!
回答1:
Your are right. Recording API takes some time for update. There is two way that came to my mind.
- always get steps by History API. I mean when activity is running just increase the checking rate of History API. Advantage of this is though it is taking some time, user always the same count.
- another way is bit more complex. store your Sensors Step count with time & apply some logic whether or not you need to add & show this to user.
Sorry for the long text.
来源:https://stackoverflow.com/questions/34739599/google-fit-recording-api-delay