How do I get the CURRENT orientation (ActivityInfo.SCREEN_ORIENTATION_*) of an Android device?

后端 未结 8 2006
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 03:05

I would like to find out the detailed orientation of a device, preferably one of SCREEN_ORIENTATION_LANDSCAPE, SCREEN_ORIENTATION_PORTRAIT, S

8条回答
  •  清歌不尽
    2020-11-27 03:17

    I ended up using Zoltán's answer above, which works great, except when I tried it on a tablet (a Samsung P6210 Galaxy Tab 7.0 Plus). In portrait mode, it returned SCREEN_ORIENTATION_REVERSE_PORTRAIT. So in the else statement (if natural orientation is landscape) I swapped the cases for ROTATION_90 and ROTATION_270, and everything seems to work fine. (I don't have enough reputation to post this as a comment to Zoltán's answer.)

提交回复
热议问题