I do not ask a question. I am going to post this in case anyone else comes across this issue. If you follow the Android API manual for the rotation sensor, you will encounter an error. In particular: java.lang.IllegalArgumentException, because some devices return an array with five values. You can probably fix it now that you know it, but still here's how to do it:
private int rotateVectLength;
private float[] jRotateVectValues = null;
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
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);
}
}
Hope this helps someone. Hurrah!
The documentation indicates:
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)
values [3], initially optional, will always be present at SDK Level 18 onwards. Values [4] is the new value added to SDK Level 18.
source
share