How to detect exact orientation of device in Froyo?

后端 未结 5 1785
执念已碎
执念已碎 2021-01-15 05:18

I\'m trying to temporarily lock the orientation of the Android device, where most of the time it changes with the sensor. So what I want to do is figure out what the current

5条回答
  •  臣服心动
    2021-01-15 06:04

    I found another simple solution on this website: http://sagistech.blogspot.ch/2010/12/finding-android-screen-orientation.html

    There are multiple way to get Android screen orientation (landscape/portrait), however some of them are problematic: this.getWindowManager().getDefaultDisplay().getOrientation() Is deprecated

    this.getWindowManager().getDefaultDisplay().getRotation() Works only from Android 2.2

    I Found this to be the best resource until now, since it's exists since API 1 & it's not deprecated, yet: this.getResources().getConfiguration().orientation

    Compare it with:

    • Configuration.ORIENTATION_LANDSCAPE
    • Configuration.ORIENTATION_SQUARE
    • Configuration.ORIENTATION_PORTRAIT

    For me it worked.

提交回复
热议问题