我开发了通过步行计算卡路里消耗的应用程序,因为我使用 SensorEventListener (ACCELEROMETER) 我从 X、Y、Z 中得到三个值。我的问题是如何使用这三个 X、Y、Z 计算脚步。这是我获取 X、Y、Z 值的代码。我也使用 GPS。但我需要在 Android guyzz PLZ 中使用计步器来计算步数,请帮助我。
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) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_workout);
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
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
Toast.makeText(getApplicationContext(), "Start",
Toast.LENGTH_LONG).show();
}
});
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);
}
}
}