Android Studio 3.6.
I want my app to be always in portrait
mode. So in my AndroidMainfest.xml
:
<activity android:name=".activity.SplashActivity" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
I run the app and SplashActivity
shows in portrait
mode. Nice. But the editor shows the following error:
Expecting android:screenOrientation="unspecified"
Why?
Since as a part of functionality app supports portrait orientation, so added tools:ignore="LockedOrientationActivity" in the manifest to remove the lint warning related to screen orientation.
Try this: android:screenOrientation="fullSensor" The orientation is determined by the device orientation sensor. The orientation of the display depends on how the user is holding the device. This should be what you want. Also for more options check out this link-Activity Element.
The screen orientation attribute is provided by the activity element in the Android Manifest. Xml file. The orientations provided by the activity are Portrait, Landscape, Sensor, Unspecified and so on. To perform a screen orientation activity you define the properties in the Android Manifest.
In your manifest tag (just under xmlns:android="http://schemas.android.com/apk/res/android"
), put
xmlns:tools="http://schemas.android.com/tools"
Then inside the application tag, put
tools:ignore="LockedOrientationActivity"
it only affects Android Studio 3.6+
What is the Issue here? This issue occurs because android framework wants user to control the app orientation himself it is not advised to restrict your app orientation for example if a user wants to use the app in landscape orientation he just flips the device and sensors will do the work but when a developer restrict screen orientation, even when rotation sensor works app will stay in pre-defined state, in a way you are restricting user's device capabilities.
What to do now? You have two options., First is to ignore the error as it won't cause any build failure even I am doing the same and apk/aab generation is as usual Another Option is to provide Landscape Layouts or to handle the rotation like in some apps which recognize if orientation gets changed they will prompt the user to change the orientation as the app is not supported in such orientation
It may change in future => at present it is not effecting our build process but it might change in future
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