Set orientation - native camera/maps some other apps too - android

I am developing an application to take photos using the Android native camera and load maps, etc.
The orientation of the maps has been changing as I change it, but what I actually need is to have only landscape orientation even on native apps since my whole application is landscape-only.
But how can I set the orientation?

In the AndroidManifest.xml file you specify the acceptable orientations for your application.
To force your activity to remain in landscape mode simply include the android:screenOrientation tag in your activity's definition tag.
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="landscape">

Related

Android SetRequestRotation flips Activity landscape to portrait when auto rotate enabled

I am trying to setRequestOrientation to a portrait but Activity rotates to landscape and set to portrait when auto-rotate enabled.
The Activity will support both landscape and portrait mode.
The problem will happen above Android 7.0.
Try setting the screen orientation to follow the previous set orientation like this
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="behind" >
</activity>
Set it to behind.
The default android:screenOrientation is unspecified. This means
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 some tablets, for example, the default that the system will choose is landscape, so the system may be auto-rotating to landscape as soon as you start the activity, and then flipping from landscape to portrait when you do your setRequestOrientation.
So to prevent the system from behaving this way, you could try choosing the android:screenOrientation for each of those activities in your android manifest like:
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="locked" >
</activity>
or
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="behind" >
</activity>
depending on your app requirements. See the Google documentation for more information on these and other options.

Android Studio - landscape only but still rotate

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>

Definition of android device natural orientation

I want to change the basic orientation of an android device. Curently its startup orientation is landscape, I need portrait.
I managed to modify the acceleration values so that the axis now point to where I want them to point to.
But the device seems to have its own definition of up and right. Now I have to change this.
Can someone tell me where this can be done? I guess there is a config file out there that I can't identify.
There are millions of hits searching for this problems. Unfortunately they all deal with java programming, not with OS code.
In your manifest file under activity tag that is on which screen you want to apply that orientation.
For portrait
android:screenOrientation="portrait"
For landscape
android:screenOrientation="landscape"
Add this lines of code in Androidmanifest.xml for the orientation
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="landscape">

How to avoid changing of image and layout position when changing from portrait to landscape mode in android

I have problem while using lanscape mode in android.How to avoid changing of image position changing from portrait to landscape mode in android.Normally landscape4 and portrait mode is good.If we goes from one mode to another then position of images are changed. Please help me
The activity in which you are showing image, register that Activity in Android Manifest file as:
<activity
android:name="com.android.YourActivity"
android:screenOrientation="portrait">
</activity>
In this way, it will force the activity to stay in Portrait mode only.
The orientation changes causes the running activity to restart.The restart behavior is designed to help your application adapt to new configurations by automatically reloading your application with alternative resources that match the new device configuration. Hence resource intensive.
Depending on how you want you app to behave and the device performance you can handle the orientation change(config changes as a whole) in following ways:
Fixed orientation: If you want your app to have a fixed orientation in landscape or portrait mode. For this you need to set this attribute in the manifest file under the activity tag.
android:screenOrientation="portrait"
or
android:screenOrientation="landscape"
Handling the Configuration Change Yourself: You can handle the orientation change yourself if your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity.
For this you need to declare this in the manifest file:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"/>
and you need to override the onConfigurationChanged() method of the activity.
** use this as the last resort as every thing needs to be handled by you.
Default behavior: You can let android handle the config changes choosing the alternative resources from the resource folder. You just need to provide these alternate resources for landscape and portrait mode.

problem on portrait mode of a WebView based application

I have a Android web application for Tab by using WebView. My everything is developed on server side by using asp.net.
the application design is quite ok on landscape mode but its break on portrait mode.
What should I do now, design every page for portrait mode or something.
just add android:screenOrientation="portrait" to the activity (in ur case in webview activity)in the AndroidManifest.xml. For example:
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
or programmaticaly
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Fixed Portrait orientation
dolet me know it works or not

Categories

Resources