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:
- public void onStep() {
- if (mIsMetric) {
- mCalories +=
- (mBodyWeight * (mIsRunning ? METRIC_RUNNING_FACTOR : METRIC_WALKING_FACTOR))
- // Distance:
- * mStepLength // centimeters
- / 100000.0; // centimeters/kilometer
- }
- else {
- mCalories +=
- (mBodyWeight * (mIsRunning ? IMPERIAL_RUNNING_FACTOR : IMPERIAL_WALKING_FACTOR))
- // Distance:
- * mStepLength // inches
- / 63360.0; // inches/mile
- }
- notifyListener();
- }
Distance Walked:
Similarly, DistanceNotifier.java [2] gives the distance with the following method:
- public void onStep() {
- if (mIsMetric) {
- mDistance += (float)(// kilometers
- mStepLength // centimeters
- / 100000.0); // centimeters/kilometer
- }
- else {
- mDistance += (float)(// miles
- mStepLength // inches
- / 63360.0); // inches/mile
- }
- notifyListener();
- }
Simply give it a run in your own IDE, it works fine.
Footnotes
[1] bagilevi/android-pedometer[2] bagilevi/android-pedometer