我需要计算行走的步数,因此我正在使用加速度计。在以上代码中,我获得了加速度传感器的x、y、z值。这是我目前为止所做的。我的问题是,如何通过x、y、z来计算行走的步数? 我从上面的链接获取以下代码:
http://pedometer.googlecode.com/svn/trunk/src/name/bagi/levente/pedometer/Pedometer.java
我的代码:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class Accelerometer extends Activity implements AccelerometerListener {
private static Context CONTEXT;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CONTEXT = this;
}
protected void onResume() {
super.onResume();
if (AccelerometerManager.isSupported()) {
AccelerometerManager.startListening(this);
}
}
protected void onDestroy() {
super.onDestroy();
if (AccelerometerManager.isListening()) {
AccelerometerManager.stopListening();
}
}
public static Context getContext() {
return CONTEXT;
}
/**
* onShake callback
*/
public void onShake(float force) {
Toast.makeText(this, "Phone shaked : " + force, 1000).show();
}
/**
* onAccelerationChanged callback
*/
public void onAccelerationChanged(float x, float y, float z) {
((TextView) findViewById(R.id.x)).setText(String.valueOf(x));
((TextView) findViewById(R.id.y)).setText(String.valueOf(y));
((TextView) findViewById(R.id.z)).setText(String.valueOf(z));
}
}
请帮帮我。