I tried this, not work, I always got 0 degree
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenOrientation = display.getRotation();
If use SensorManager, it is also not work, because it will not be triggered if I don't move the phone
mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
}
};
Update
Please try the complete demo
https://github.com/sochap/getorientationquestdemo
Since the display is not changed, use display to determine that is impossible
I am going to get device orientation, not display orientation
OrientationEventListener
will work, but not at onCreate