Error de sensor de rotación Android sensor

No estoy haciendo una pregunta. Voy a publicar esto en caso de que alguien más se tropieza con este problema. Si sigue la guía de la API de Android para el sensor de rotación, se producirá un error. Específicamente: java.lang.IllegalArgumentException, porque algunos dispositivos devuelven una matriz con valores CINCO. Probablemente puede arreglar esto ahora que lo sabe, pero de todos modos aquí es cómo hacerlo:

private int rotateVectLength; private float[] jRotateVectValues = null; public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { // convert the rotation-vector to a 4x4 matrix. the matrix // is interpreted by Open GL as the inverse of the // rotation-vector, which is what we want. if(jRotateVectValues == null) { rotateVectLength = event.values.length; jRotateVectValues = new float[rotateVectLength]; } for(int i = 0; i < rotateVectLength; i++) { jRotateVectValues[i] = event.values[i]; } SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); } } 

Espero que esto ayude a alguien. ¡Aclamaciones!

La documentación señala esto:

 values[0]: x*sin(θ/2) values[1]: y*sin(θ/2) values[2]: z*sin(θ/2) values[3]: cos(θ/2) values[4]: estimated heading Accuracy (in radians) (-1 if unavailable) 

los valores [3], originalmente opcionales, siempre estarán presentes desde el nivel 18 del SDK. values ​​[4] es un nuevo valor que se ha agregado en SDK Nivel 18.

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.