1

I am creating a step tracking application where I get the data from GoogleFit. I use history API for that and get teh data of the steps during the day.

Now in my app the user can set a goal he wants to walk in one day, Say 10000/20000 steps in a day. And I wish to show a notification to the user whenever he/she completed the goal for the day.

Few ideas I looked into are : 1. I tried looking into goal API but there is shows as per the official documentation that we can read the goal user has set in google fit app, and we cannot set our custom goal.

  1. The second approach we thought of is to set alarm manager at particular time intervals and get the data from history API and then check if the goal is completed or not and then show the notification. But here there will be many wake calls to the phone and which I feel isn't a good idea.

Need help in getting a better approach for this use case, and if the 2nd method is good then how can we make sure there aren't many wake-call.

Parth Anjaria
  • 3,961
  • 3
  • 30
  • 62
  • 1
    Interesting question. I found [this](https://stackoverflow.com/questions/34472700/using-type-step-counter-in-a-background-service/34820076) which has 3 completely different answers. Check them out and see if that gives you any ideas – Vucko Aug 02 '19 at 08:59

1 Answers1

0

You can try this approach

  1. you can create a database which store date and completed steps also store today's goal(if the goal is the day wise)

  2. on each day start you can get steps from google fit and store in your DB by adding in previous steps like (todaysTotalStepsFromDB + googleFitSteps)

  3. update your DB on each step or you can set some interval, after that you will update your DB with today's total steps

  4. when user reach their goal(1000/2000 steps) you can show notification

  5. for that I would like to suggest to use a firebase real-time database, so you can notify each and every update of DB

Priyanka
  • 3,369
  • 1
  • 10
  • 33