QNA > H > How To Calcuate Burned Calories And Distance After Getting Step Counts In Android Step Count Sensor

How to calcuate burned calories and distance after getting step counts in Android step count sensor

What you’re looking for is called a Pedometer, I believe and, an app similar to it is available Pedometer - Apps on Google Play.

Fortunately, the source code is public as well bagilevi/android-pedometer

Burned Calories:

The function in CaloriesNotifier.java [1] that calculates the burned calories is as follows:

  1. public void onStep() { 
  2. if (mIsMetric) { 
  3. mCalories +=  
  4. (mBodyWeight * (mIsRunning ? METRIC_RUNNING_FACTOR : METRIC_WALKING_FACTOR)) 
  5. // Distance: 
  6. * mStepLength // centimeters 
  7. / 100000.0; // centimeters/kilometer 
  8. else { 
  9. mCalories +=  
  10. (mBodyWeight * (mIsRunning ? IMPERIAL_RUNNING_FACTOR : IMPERIAL_WALKING_FACTOR)) 
  11. // Distance: 
  12. * mStepLength // inches 
  13. / 63360.0; // inches/mile  
  14. notifyListener(); 

Distance Walked:

Similarly, DistanceNotifier.java [2] gives the distance with the following method:

  1. public void onStep() { 
  2. if (mIsMetric) { 
  3. mDistance += (float)(// kilometers 
  4. mStepLength // centimeters 
  5. / 100000.0); // centimeters/kilometer 
  6. else { 
  7. mDistance += (float)(// miles 
  8. mStepLength // inches 
  9. / 63360.0); // inches/mile 
  10. notifyListener(); 

Simply give it a run in your own IDE, it works fine.

Footnotes

[1] bagilevi/android-pedometer[2] bagilevi/android-pedometer

Di Mattah Yeager

Quale percentuale di americani ha ucciso qualcuno? :: Perché OnePlus è vietato in India?
Link utili