I've seen a few other questions similar to this but no answers.
Rotating from portrait to landscape (either direction) and back again, we get the helpful call to onConfigurationChanged().
However, when rotating from landscape to landscape (through 180 degrees) onConfigurationChanged() is not called.
I've seen mention of using OrientationEventListener but this seems flakey to me because you can rotate quickly around without triggering a display orientation change.
I've tried adding a layout change listener, but with no success.
So the question is, how to reliably detect such a change in landscape orientation?
You can detect this change in orientation on Android as well as iOS with the following code: var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; window.
This feature can be enabled or disabled under 'Launcher' > 'Settings' > 'Display' > 'Auto-Rotate screen'. There are third-party apps in the Google Play Store which allow force and lock screen orientation.
Find and turn on the "Auto-rotate" tile in the quick-setting panel. You can also go to Settings > Display > Auto-rotate screen to turn it on. Your phone screen should rotate automatically now if nothing is wrong with the sensors.
When set to landscape the screen is fixed but when set to sensor landscape it can rotate to any orientation.
OrientationEventlistener won't work when the device isn't rotating/moving.
I find display listener is a better way to detect the change.
DisplayManager.DisplayListener mDisplayListener = new DisplayManager.DisplayListener() {
@Override
public void onDisplayAdded(int displayId) {
android.util.Log.i(TAG, "Display #" + displayId + " added.");
}
@Override
public void onDisplayChanged(int displayId) {
android.util.Log.i(TAG, "Display #" + displayId + " changed.");
}
@Override
public void onDisplayRemoved(int displayId) {
android.util.Log.i(TAG, "Display #" + displayId + " removed.");
}
};
DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
displayManager.registerDisplayListener(mDisplayListener, UIThreadHandler);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With