I have a problem with orientation in android. The device orientation is the landscape that I set in the AndroidManifest.xml file.
android:screenOrientation="landscape"
I also hold the device in the landscape, so everything (layouts, views, etc.) is in landscape mode as I wanted. But only when I hold the device in the portrait does it give me the values ββthat I need.
Iβve modified some code from the Internet and it works for HTC 3D EVO, Nexus 7 and Samsung Galaxy S3, but not on the Galaxy Tablet 10 ".
I found this post. Is Android Orientation Sensor different for different devices? The accepted answer suggests getRotation () and remapCoordinateSystem () methods, but no mention of how.
This is how I ended up.
SensorManager.getRotationMatrix(Rmat, Imat, gData, mData); SensorManager.remapCoordinateSystem(Rmat, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R2); // Orientation isn't as useful as a rotation matrix, but // we'll show it here anyway. SensorManager.getOrientation(R2, orientation); float incl = SensorManager.getInclination(Imat); FontTextView pitchText = (FontTextView)findViewById(R.id.pitch_text); if((int)(orientation[1]*90) <= -110 && !newQuestionIsActive) { newQuestionIsActive = true; pitchText.setText("Bring new question"); } else if(Math.abs((int)(orientation[2]*90)) <= 200 && (int)(orientation[1]*90) >= -30 && newQuestionIsActive) { newQuestionIsActive = false; pitchText.setText("Not Correct!"); } else if(Math.abs((int)(orientation[2]*90)) > 200 && (int)(orientation[1]*90) >= -30 && newQuestionIsActive) { newQuestionIsActive = false; pitchText.setText("Congratulations!"); }
Now, how should I use getRotation () in this code? And there may be a brief explanation, it would be useful to understand why the 3 devices mentioned are working fine, but not the Galaxy Tablet.
This issue is described in the Android documentation.
Finally, if your application maps sensor data to an on-screen display, you need to use the getRotation () method to determine screen rotation, and then use remapCoordinateSystem () to map the sensor coordinates to screen coordinates. You need to do this even if your manifest specifies only portrait display.
http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html