I am using a android phone for my development of a kiosk system. The handy uses as standard the portrait mode and will switch with the sensors to landscape if I rotate it to my needs. My problem is that this device programmed layout will do many side by side effekts in runtime because it will always switch to portrait and then remembers the sensor orientation and switches back to landscape. This means the implementation of portrait mode is not very comfortable for my development.
Now I saw in the dev tools the configuration app which shows me a device config:
orientation=1
My question is: Which file I have to edit to change the device orientation to standard landscape so that the above app will show me landscape. (phone is rooted)
I want to change global from phone portrait mode to tablet landscape mode and not only a single application!
What you need to do is edit your AndroidManifest.xml file and specify the orientation for your activity, as well as handle orientation changes yourself:
<activity android:name="MyActivity"
android:label="#string/app_name"
...
android:configChanges="orientation|keyboardHidden"
...
android:screenOrientation="landscape">
Then your activity will always run in a landscape mode regardless of the device orientation.
EDIT: If you want programmatically to enable/disable auto-rotation, then you can use this code:
public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled)
{
Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
However note that this will affect all applications running on the device.
Hi is this what you are looking for? this would leave the application orientation as landscape.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
This thread is 5 yrs old - am answering to help someone reached here later..
I guess every ans here talks about application specific orientation change. Here's what you should consider for changing orientation for the full device
Runtime: In /system/build.prop add:-
# Makes portrait only
persist.panel.orientation=90
To add in Build tree: Add same in
device/<vendor>/<processor>/system.prop
if you want to keep the orientation as landscape, add this in your Manifest.xml:
<activity android:name="MyActivity" android:screenOrientation="landscape"></activity>
Related
I am using an application for meditation on daily basis, today i was surprised by it because when i rotate screen, App goes to landscape mode, Although the Automatic rotation was off from my settings, How it can happen?
Is there something like Force device to change orientation?
And If default device rotation is off then how app can know that device orientation is changed?
I double checked my phones settings of Auto-Rotation and they were off.I am using Kitkat device.
In AndroidManifest.xml file set activity tag, screenOrientation attribute to fullSensor like this:
<activity
android:name=".MyActivity"
android:screenOrientation="fullSensor" />
Yes. you can.
in onCreate method type
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this will do the magic.
I want to be able to select WHICH direction on landscape mode to be rotated to. I have a particular situation where the device will be landscape, but it appears upside down to what I want. The accelerometer does not seem to be working. Please note: this is for a specific enterprise app that is not going on the Google play store.
My code so far (in the manifest, under the application tag):
android:screenOrientation="landscape"
I have looked at the following posts:
How can i rotate the particular view landscape or portrait programatically in android?
Android screen orientation: forcing landscape?
your line should be in activity tag (each if you have few). Also you might use
android:screenOrientation="sensorLandscape"
API 9, on older versions it will be "normal" landscape
Following is code which i used to display your activity into landscape mode only
<activity android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:name="yourActivty"/>
I want to set the orientation of my activity to reversePortrait. To do this, i set the following value in the activity of my manifest file:
android:screenOrientation="reversePortait"
But this only works you enable "Screen Rotation" from the settings of the device. If "Screen Rotation" is disabled it shows the screen in portrait mode instead of reverse portrait.
Please help.
insert
android:configChanges="orientation"
below
android:screenOrientation="reversePortait"
It means the developer takes the whole control of the screen rotation, not the android pattern
I would like for my activity not to rotate when the device is turned.
Using
android:screenOrientation="nosensor"
does disable orientation changes, but with one caveat: the activity switches to portrait mode. I just want it to keep the current orientation (e.g., if the screen was in landscape when the activity was started, then stay in landscape mode even when the device is rotated). This is not what "nosensor" seems to be doing. It seems to simply be the exact same behavior as "portrait". Am I using it wrong?
I've tried using setRequestedOrientation( getRequestedOrientation ), but if the current requested orientation is undefined, then my activity is going to rotate. I just want too "lock" the effective screen rotation.
What you can do is to tell Android that you are going to handle the orientation configuration change on your own. You do it by specifying orientation for the android:configChanges attribute of the activity tag.
<activity android:name=".MyActivity"
android:configChanges="orientation"
android:label="#string/app_name">
See this link for more information.
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange
As to why nosensor would not work, is because it's mentioned as below in the documentation.
The orientation is determined without reference to a physical
orientation sensor. The sensor is ignored, so the display will not
rotate based on how the user moves the device. Except for this
distinction, the system chooses the orientation using the same policy
as for the "unspecified" setting.
and as to what unspecified is in the documentation
The default value. The system chooses the orientation. The policy it
uses, and therefore the choices made in specific contexts, may differ
from device to device.
In my manifest I've setup an activity restricted to portrait orientation. But I need to remove this restriction on condition. So, how do I achieve removing orientation restrictions programmatically ?
upd: my present settings are:
<activity
android:name=".activity.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="orientation">
/**
* Defines whether the device being used is a tablet and if so adds horizontal orientation option.
*/
protected void _updateScreenOrientationModes(){
if(((MyApplication) getApplication())._isTablet == true)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
Whether or not you've set android:screenOrientation in your Manifest, you can programmatically set the orientation with Activity.setRequestedOrientation().
In essence, "removing the restriction" is accomplished by
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
after which the Activity will exhibit the default behavior of changing screen orientation when the physical device orientation changes.
It's likely, however, that you want to actually match the current physical device orientation at the same time. I haven't tried it, but I'm pretty sure that if all you did was the above, if the device was physically in a landscape orientation when you did it, then you'd stay in portrait mode until you physically moved the device to portrait and back to landscape.
What I would do is be sure to set android:configChanges="orientation" in your Manifest and override Activity.onConfigurationChanged(), in which you can, according to your condition, either perform the orientation change or cache the orientation. Then whenever your condition changes, you'll have the current physical orientation handy so you can change it at that point if necessary.
Programmatically you can change your screen orientations by using "setRequestedOrientation()"
In your java class write the following code as per your condition required.....
To change to portrait mode, use the ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE constant:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
To change to portrait mode, use the ActivityInfo.SCREEN_ORIENTATION_PORTRAIT constant:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I'm going to leave my other answer, as it addresses the more general question that you asked. However, in a comment to someone else you said:
I need to allow tablets to have both orientations and handsets only portrait
Your particular case is actually easier than the general case: Remove both android:screenOrientation="portrait" and android:configChanges="orientation" from your Manifest to allow the default behavior. Then, during startup, if the device is a handset, force portrait orientation with
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
A device will obviously never change between being a tablet or a handset at runtime, so you only need to do this once, at startup. Tablets will get the default behavior, so whatever physical orientation the device is in, that's what they'll use. Handsets will be forced into portrait and stay that way.