Android: Orientation Issue - android

I have an activity that shows a video. I want this view to show only on landscape, so I have my AndroidManifest.xml as follow:
<activity
android:name="uk.co.tangent90.ciscoDelegateBag.android.activities.ViewVideoActivity"
android:label="#string/registerViewTitle"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation" >
</activity>
It is working almost fine:
If I am in portrait, the view rotates as expected.
If I am already in landscape, can happen 2 things:
The view remain as it is. OK.
The view rotate 180 degrees. NOT OK
It is depending on if I have the front camera in the right or in the left. So it is like android only recognizes ONE landscape orientation.
Has anybody have this problem before? Any easy way to fix it?
Thanks.

Use
android:screenOrientation="sensorLandscape"
Refer <activity> documentation for values screenOrientation can take.

Can you try the following?
android:configChanges="keyboardHidden|orientation|screenSize"

Use screenSize if you are using minimum sdk version above 13.
If your application targets API level 13 or higher (as declared by the
minSdkVersion and targetSdkVersion attributes), then you should also
declare the "screenSize" configuration, because it also changes when a
device switches between portrait and landscape orientations.

Android recognizes only one rotation as landscape, the other, 180° degrees rotated "landscape" orientation is called "reverseLandscape", you can only use one of them, in fact, most of the apps that show videos only work in one orientation.
EDIT: try as Rajesh said "sensorLandscape"

Related

Android choose particular landscape orientation

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"/>

Android activity not rotating on phones (but does on tablets)

I have an activity that does not rotate on some devices, but does rotate on others.
Specifically it rotates on tablets tested so far, but not on phones. My other activities with the same manifest parameters do rotate as expected.
This view has a viewpager as well as admob ads. Is there a known bug/feature with these layout elements that can override rotation parameters? I don't have anything saying the orientation should stick to landscape or portrait in the manifest or in the code.
If there isn't anything known, I can post code later.
The answer is that this theme
android:theme="#android:style/Theme.Translucent.NoTitleBar"
doesn't allow rotation on certain screen sizes
In manisfest insert the activity parameter android:configChanges="orientation" and not insert the screenOrientation parameter.

Android: Fix orientation based on the position of the device

I was wondering if it is possible to fix the orientation of a layout based on the position of a device. For example if an app is launched while in a portrait position, the app is fixed in portrait. If the app is launched in landscape the orientation is fixed to landscape.
I understand you can fix the orientation to either portrait or landscape in the manifest but is there a way to fix the orientation dynamically based on the the device position?
I believe what you want is
android:configChanges="keyboardHidden|orientation"
in the manifest. I haven't tested it but I think that tells Android not to handle those changes. Hope this helps!

lock screen rotation but detect it anyway

I m building an app which an a main layout in portrait format
I locking orientation with
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
However, I need to detect screen orientation changes anyway because I want to load another Activity if the screen is rotated.
How to do that ?
I tryed onConfigurationChanged but it s never called.
Some things to look at if onConfigurationChanged isn't firing:
When you declare the manifest, make sure you have defined at least orientation and screenSize for the activity configChanges. Like this:
<activity android:name="com.test.act" android:configChanges="orientation|screenSize">
Make sure the device doesn't have rotation blocked. For example if you are using a Nexus 7:
http://www.howtogeek.com/120056/how-to-enable-landscape-orientation-on-the-nexus-7s-home-screen/

How to change the device orientation in android?

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>

Categories

Resources