Reputation: 31
I have built an Android application that is only designed to be used in portrait mode. I am aware that there are a few workarounds, one of which is specifying the orientation in AndroidManifest.xml
as follows:
android:screenOrientation="portrait"
The other solution is to call setRequestedOrientation()
in the onCreate()
method. I use Kotlin, and I added this line before the super call and setContentView()
:
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
This method works on mobile devices but not on tablets. I have been testing my app on a virtual Pixel tablet with API 34. The problem is when I launch the app while in landscape mode, instead of locking the app in portrait mode or changing the screen orientation, my app is letterboxed, and the screen is still in landscape mode. When I launch the app while in portrait mode, the app works as expected. However, when I rotate the tablet while the app is running, a rounded button appears, prompting the user to switch to landscape mode. This action letterboxes my app in landscape mode again, which is not desired.
After scrolling through the Android Developers' documentation, apparently:
On Android 12 (API level 31) and higher, device manufacturers can configure their devices to ignore orientation restrictions specified by apps and instead use the restrictions to enforce compatibility modes.
What I want to achieve is to force the screen orientation to portrait at all times. When the user launches the app in landscape mode, the app should open in portrait mode. This issue does not appear on the iPad but on Android tablets. Is there any fix to this problem? I have searched for similar questions on Stack Overflow, but none of the solutions worked.
Upvotes: 3
Views: 259