getting device orientation in honeycomb
Question
The function SensorManager.getRotationMatrix(...) does not work in Android 3.0+. I have run the code below on a wide range of phones/tablets running android 2.x, and it works just fine.
public void onSensorChanged(SensorEvent event) {
float[] magnetic = event.values;
if( accelerometer != null ) {
float[] array = new float[9];
SensorManager.getRotationMatrix(array, null, accelerometer, magnetic);
// in 3.0+, 'array' contains all 0's here, which is bad
SensorManager.getOrientation(array, orientation);
}
}
Solution
It turns out that magnetic[0] contains a number between 0 and 360 containing the bearing.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow