I would like to find out the detailed orientation of a device, preferably one of SCREEN_ORIENTATION_LANDSCAPE
, SCREEN_ORIENTATION_PORTRAIT
, SCREEN_ORIENTATION_REVERSE_LANDSCAPE
, SCREEN_ORIENTATION_REVERSE_PORTRAIT
from ActivityInfo
or equivalent.
Some of the answers here on StackOverflow included
getWindowManager().getDefaultDisplay().getRotation()
but this doesn't really tell me whether the device is in portrait or landscape mode, only how it's turned with reference to its natural position - which in turn can be landscape or portrait in the first place.
getResources().getConfiguration().orientation
returns one of the following three: ORIENTATION_LANDSCAPE
, ORIENTATION_PORTRAIT
, ORIENTATION_SQUARE
, which then doesn't really tell me which way the phone is turned (whether it's upside down or which of the sides it's turned to).
I know I could use the latter in combination with DisplayMetrics
to find out the device's natural orientation, but is there really no better way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…