我一直有這個問題太久了。這段代碼應該輸出加速度計的dx,dy,dz和dx的運行總數。它還應輸出方位角,俯仰角和俯仰角。在Android 2.1中使用getRotationMatrix和getOrientation
I've used the information given here,但無濟於事。
此代碼無法正確輸出音調,方位角或滾動。它分別輸出0.0,-0.0,-0.0的最後三個文字查看。
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
accelerometerValues = event.values.clone();
case Sensor.TYPE_MAGNETIC_FIELD:
geomagneticMatrix = event.values.clone();
sensorReady = true;
break;
default:
break;
}
if (geomagneticMatrix != null && accelerometerValues != null && sensorReady) {
sensorReady = false;
float[] R = new float[16];
float[] I = new float[16];
SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);
float[] actual_orientation = new float[3];
SensorManager.getOrientation(R, actual_orientation);
tvXCoordinate.setText(accelerometerValues[0] + "");
tvYCoordinate.setText(accelerometerValues[1] + "");
tvZCoordinate.setText(accelerometerValues[2] + "");
floatXTotal += accelerometerValues[0];
tvXTotal.setText(floatXTotal + "");
tvAzimuth.setText(actual_orientation[0] + "");
tvPitch.setText(actual_orientation[1] + "");
tvRoll.setText(actual_orientation[2] + "");
}