I used SensorManager to get values :
orientationValues[0]: azimuth, rotation around the Z axis.
orientationValues[1]: pitch, rotation around the X axis.
orientationValues[2]: roll, rotation around the Y axis.
and put them to Text Views.
It seems to work on some devices i have tested it but not on Xperia Neo V and i hope you could tell me why and how can i make it work.
- Code: Select all
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE)
return;
// Gets the value of the sensor that has been changed
switch (sensorEvent.sensor.getType()){
case Sensor.TYPE_ACCELEROMETER:
gravity = sensorEvent.values.clone();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
magnetic = sensorEvent.values.clone();
break;
}
if (gravity != null && magnetic != null){
// checks that the rotation matrix is found
boolean success = SensorManager.getRotationMatrix(inR, I, gravity, magnetic);
if (success){
// Re-map coordinates so y-axis comes out of camera
SensorManager.remapCoordinateSystem(inR, SensorManager.AXIS_X,
SensorManager.AXIS_Z, outR);
// Finds the Azimuth and Pitch angles of the y-axis with
// magnetic north and the horizon respectively
SensorManager.getOrientation(outR, orientVals);
orientVals[0] = orientVals[0]*rad2deg;
orientVals[1] = orientVals[1]*rad2deg;
orientVals[2] = orientVals[2]*rad2deg;
x.setText(Float.toString(orientVals[0]));
y.setText(Float.toString(orientVals[1]));
z.setText(Float.toString(orientVals[2]));
}
}
}
Sorry about my English
Thanks in advance


