我想检测用户是否在移动 - 无论是行走还是跳跃
我找到了这个代码示例
private final SensorEventListener sensorEventListener = new SensorEventListener() {
double calibration = SensorManager.STANDARD_GRAVITY;
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
double x = event.values[0];
double y = event.values[1];
double z = event.values[2];
double a = Math.round(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)
+ Math.pow(z, 2)));
currentAcceleration = Math.abs((float) (a - calibration));
它给出的读数在 0.01 到 0.2 G 之间——我可以用这个例子来检测运动吗?也许有点跑题了?- 抱歉,如果是的话!