我需要在步行時計數步數。以便我使用加速度計。在上面的編碼中,我得到了加速計傳感器的x,y,z值。這是我迄今爲止所做的。我的問題是由x,y,z如何計算步行時的步數? 我從鏈接如何在android中使用加速度計步數
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));
}
}
請幫助我。
使用下面的代碼有啥這裏的問題是什麼?什麼不工作? – corroded 2011-05-26 04:20:44
我不知道如何計算加速度計的x,y,z值的步數。那是我的問題。 – 2011-05-26 04:23:31
@腐蝕:請幫助我。 – 2011-05-26 04:39:20