Android 加速度传感器 怎么转换成角度
的有关信息介绍如下:sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
aSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensor = sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
sm.registerListener(myListener, aSensor, SensorManager.SENSOR_DELAY_NORMAL);
sm.registerListener(myListener, mSensor,SensorManager.SENSOR_DELAY_NORMAL);
SensorEventListener myListener =new SensorEventListener() {
publicvoid onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
magneticFieldValues = sensorEvent.values;
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
accelerometerValues = sensorEvent.values;
float[] values =newfloat;
float[] R = newfloat;
SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues);
SensorManager.getOrientation(R, values);
//这里 values,values,values里边的数据就是x y z 轴 分别的角度
}
publicvoid onAccuracyChanged(Sensor sensor,int accuracy) {}
};