Android getOrientation() function says that:
However I get different value ranges when testing with an emulator (Nexus 5 API 25)/device(Samsung API 21). I used Logcat to print the values. The pitch values I get are from -pi/2 to pi/2. With the screen pointing to the sky, the value ranges from 0 to -pi/2, with the screen pointing to the ground, it ranges from 0 to pi/2. And the roll goes above pi/2.
Why am I getting values different from the documentation?
My code is as following:
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, mAccelerometerReading,
0, mAccelerometerReading.length);
}
else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, mMagnetometerReading,
0, mMagnetometerReading.length);
}
if (mAccelerometerReading != null && mMagnetometerReading != null) {
// Update rotation matrix, which is needed to update orientation angles.
mSensorManager.getRotationMatrix(mRotationMatrix, null,
mAccelerometerReading, mMagnetometerReading);
mSensorManager.getOrientation(mRotationMatrix, mOrientationAngles);
Log.d("sensor", Float.toString(mOrientationAngles[1]));
}
Please Compare with the Real devices only(Preferable) Because Something Emulator gives different values than the Expected And here I am attaching one reference Please Have a look.
Reference 1
Reference 2
What you have do is:-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With