Android WebView app: Set or restrict orientation by code in Android Studio

Man surfing the Internet using smart phone

Orientation restrictions restrict the orientation of the screen to a single orientation, preventing it from changing the orientation according to the movements of the device.

For example, if an app is in portrait mode and you turn your phone sideways, then it will not change to landscape mode. This can be useful for apps that are primarily used in one orientation.

Some WebView app users may appreciate this feature because they have trouble holding their phone or tablet with one hand and don’t want to accidentally change the orientation when they use their other hand for something else.

It could also be required by your website / web app loaded within the WebView, maybe your site only supports one orientation (e.g., often the case for games, AR apps, …).

Easy fix: Within WebViewGold (for Android), set PHONE_ORIENTATION and TABLET_ORIENTATION variables to either “portrait“, “landscape“, or “auto“.