Take the 2-minute tour ×

i develop application for calculation of calories burn by walking for that i use SensorEventListener (ACCELEROMETER) i get three value from that X,Y,Z. my question is how to calculate foot step using that three X,Y,Z. this is my code for getting X,Y,Z value. i use GPS also. but i required count step using Pedometer in Android guyzz PLZ help me.

package com.mxicoders.prashant;

import android.app.ActivityGroup;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Chronometer;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MyWorkout extends ActivityGroup implements SensorEventListener {

    ImageButton btnfacebook, btnstartwalk, btnstopwalk;
    Chronometer mchoronometer;
    Intent getintent;
    String _getname, _getage, _gethight, _getwidth;
    TextView txtx, txty, txtz;
    private SensorManager sensorManager;

    public void onCreate(Bundle savedInstanceState) {

        txtx = (TextView) findViewById(R.id.txtview_steps_myworkout);
        txty = (TextView) findViewById(R.id.txtview_distance_myworkout);
        txtz = (TextView) findViewById(R.id.txtview_calary_myworkout);
        btnfacebook = (ImageButton) findViewById(R.id.imgview_facebook_myworkout);

        btnfacebook.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent inn = new Intent(getParent(), MyworkoutFacbook.class);
                WorkoutTabGroupActivity parantActivity = (WorkoutTabGroupActivity) getParent();
                parantActivity.startChildActivity("MyworkoutFacbook", inn);

        btnstartwalk = (ImageButton) findViewById(R.id.imgbtn_start_myworkout);
        btnstartwalk.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

                sensorManager.registerListener(MyWorkout.this, sensorManager
                Toast.makeText(getApplicationContext(), "Start",


        btnstopwalk = (ImageButton) findViewById(R.id.imgbtn_stop_myworkout);
        btnstopwalk.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub



    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        // TODO Auto-generated method stub


    public void onSensorChanged(SensorEvent event) {
        // TODO Auto-generated method stub
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
            txtx.setText("X: " + x);
            txty.setText("X: " + y);
            txtz.setText("X: " + z);

share|improve this question

closed as not a real question by casperOne Sep 20 '12 at 11:41


1 Answer 1

My suggestion is that you should track variations in Global Z axis (your body up/down movement). You cannot guarentee that the user will hold the mobile in a specific orientation, so you will have to rely on experimenting. Also, you may need to monitor the speed of movement (so as not to translate car movement to foot steps for e.g.).

What I would do is:

1- Create a text file on the Mobile and record the values of X, Y & Z (in addition to GPS speed) while I am walking, with the mobile in different orientations (in my pocket, in a belt pouch, ...etc). Also, keep track of the number of steps I performed.

2- Based on this data in step one, form a formula to convert this data to number of foot steps.

share|improve this answer
Mohamed_AbdAllah i not get what you say. i just want calculation of walking if any other way it possible without using SensorEventListener. you haveany ideaabout that. –  Prashant09 Sep 18 '12 at 13:36
What I am saying is that you need to experiment to translate Sensor changes to food steps by logging and analysing your log. You can do it with GPS changes (convert travelled distance to foot steps by dividing it by an average foot step distance of say 15 cm) –  Mohamed_AbdAllah Sep 18 '12 at 13:40
Mohamed_AbdAllah ok i got but you can you give me any code or demo for that... –  Prashant09 Sep 18 '12 at 13:45
