Pregunta

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);
    }
}
¿Fue útil?

Solución

It turns out that magnetic[0] contains a number between 0 and 360 containing the bearing.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top