I have read on many sites that all i need to do to make orientation change impossible on my android activity is just put this on my manifest:
<activity
android:name="com.karutakanji.ModoCasual"
android:label="#string/title_activity_tela_inicial_multiplayer"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" >
</activity>
But when i try my activity on Genymotion and a 2560 x 1600 device, the activity is still flipping to landscape orientation(it happens right at the start of the activity). Is there something else i need to do to make orientation change impossible to my activity? Is it only a Genymotion bug? What can i do?
There must be something else interfering with your manifest settings. I just tested it and I can't switch genymotion to landscape within my activity. If I start my activity when I am in landscape, genymotion directly changes to portrait as expected.
My guess: Whatever you do in your activity in onCreate() might interfere or overwrite it.
edit: the configChanges are not important. screenOrientation is the attribute you need to "restrict" it to that orientation.
solved it: it was just aGenymotion problem. I just had to emulate the device on fullscreen mode to make the bug disappear ^^
Related
I'm currently developing an app, in which phones have forced portrait mode, while tablets support portrait mode as well as landscape mode. Some pages the layouts have respective landscape versions in the layout-land folder.
The problem
While using the app on a phone (so portrait only) and when autorotate on the phone is enabled, the landscape layout file gets loaded while the app is displayed as portrait mode.
When does this occur
To recreate this behaviour I open an activity and rotate the device. Then when I navigate to another activity, or close and open the application, the landscape layout gets loaded.
Method of forcing portrait mode
To force portrait mode on phones, I call
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
in my BaseActivity onCreate method.
Other details
targetSdkVersion: 26
using support library 26.0.0
Thank you for helping!
Edit 1:
Unfortunately using (a combination of) the following settings in the manifest file gives the same behaviour.
android:screenOrientation="sensorPortrait"
android:screenOrientation="portrait"
android:configChanges="orientation"
Edit 2:
I've now tested on multiple devices (emulator, One plus, Motorola, Samsung and some more) and this oddity only happens on a Samsung A5 (api 23) for me.
Is other Activities are also have that code?
I meant, other Activity that doesn't extends BaseActivity?
I would prefer to set in AndroidManifest.xml file in each activity tag like >> android:screenOrientation="portrait"
add this line android:screenOrientation="portrait" in your project manifest file inside activity. Hope it work well.
Try this
<activity
android:name=".Activity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_test_edit"
android:screenOrientation="sensorPortrait"
android:theme="#style/Theme.DesignDemo"
android:windowSoftInputMode="stateAlwaysHidden" />
Portrait orientation, but can be either normal or reverse portrait based on the device sensor.
Refer this link for more details :
https://developer.android.com/guide/topics/manifest/activity-element.html
As you mentioned,
phones have forced portrait mode, while tablets support portrait mode
as well as landscape mode
Set screen orientation in manifest will not work.
Use layout-land-sw600dp, layout-land-sw720dp folders for landscape view for tablets. Also please take a look at this SO thread
I want my android studio app to be landscape only, but to switch orientation when the phone is rotated.
This means that when u flip the phone 180°, it will still be landscape but will flip sides. Like the clash of clans game.
You should add the sensorLandscape screenOrientation tag to your activity in the android manifest file and you should be good to go.
android:screenOrientation="sensorLandscape"
Make sure to add this to all the activities that you want to have in landscape mode.
All you need is to go to your AndroidManifest.xml file and under each Activity add the screen orientation tag and set it to sensorLandscape. Make sure you do it for all the other activities if you want them to be in landscape too.
For Example :
<activity
android:name=".MainActivity"
android:label="#string/title_MainActivity"
android:screenOrientation="sensorLandscape">
</activity>
When I launches app, it always has same orientation.
After some seconds, maybe in splash scene, it turns to OS orientation.
I got that the orientation always 'Landscape Left' even if device was 'Landscape Right'.
That is my problem.
I expect that app launches so that it matches the orientation of os.
Not portrait or landscape problem, but 'Landscape Left' or 'Landscape Right' problem ;(
PlayerSettings like as bellow.
http://answers.unity3d.com/storage/temp/48453-orientation.png
I set 'Auto Rotation' and checked 'Landscape Right' and 'Landscape Left'.
http://answers.unity3d.com/storage/temp/48455-minsdk.png
And I also set min SDK api level 14.
I set screenOrientation="landscape" in AndroidManifest.xml
<activity android:name="myMainActivity" android:label="#string/app_name" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:icon="#drawable/app_icon" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="landscape" android:launchMode="singleTop">
Im using Unity3d 4.6.6p1
Thanks ;)
You can use this to control the orientation in the device via Code Screen.orientation.
You only need to ask wich are the current orientation and channge it to the other if you need it.
Hope It'll be helpfull to you.
With reference to the picture , The App view is tilted, seems like it is not straight, You can see the App Name as well Jaago which is titled, I changed the AVD postions from Landscape to Potrait and ViceVersa ,but that doesn't effect my App View at all..Any help in this regard.
The HomeScreen
Try to disabling "Hardware keyboard present" or removing "Keyboard lid support" for your emulator.
You can do this by going to the AVD Manager & editing the emulator you are using.
The reason for this might be related to the following bugs:
Issue 13189: Orientation does not change from landscape to portrait on Emulator on 2.3
Issue 19910: [Emulator] startActivityForResult on camera - Screen orientation remains fixed in landscape after taking picture
Issue 874: manifest screen orientation and run config emulator screen orientation don't work together
This is a bug with the Android emulator running 2.3
https://code.google.com/p/android/issues/detail?id=13189
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
*Add these lines in your Android Manifest file after declaring all activities in activity tags **
like:
<activity android:name="com.geeklabs.ActivityMain"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize" />
May be it will helps you.
I am developing an Android app that has full support for landscape mode. All of my activities have the following properties set in the manifest:
android:configChanges="keyboardHidden|locale|orientation"
android:screenOrientation="sensor"
However, if I disable rotation in the phone's Screen settings, my app still rotates when the phone is rotated. This kind of bothers me; it seems like the whole point of a system-level setting is moot if it can be overriden by an individual app. How can I fix this so it follows the system-level setting while still behaving properly if screen rotation is enabled on the phone?
You could try using
android:screenOrientation="user"
You can try other way like this ,
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
apply these attributes after the activity name in AndroidManifest.xml file.
you can add android:screenOrientation="user" and make sure there is no SCREEN_ORIENTATION_SENSOR in the java code or manifest.