I'm displaying a camera activity in Android 2.2 and I lock the screen orientation in landscape mode. Is there a way to get the device rotation?
I mean, getOrientation() always returns LANDSCAPE and getRotation() always returns 1. How can I get the actual rotation of the device even if I lock the orientation in landscape mode?
You can use the SensorManager class, see http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/
Related
I have my app's orientation forced via
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
but when I want to change layout to landscape one (when device is rotated - i get the info via OrientationEventListener) it just doesnt render it as landscape. Is there any way how to force it? Just like imagine holding your device in portait mode but the layout is landscape. but not achieved via
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
android:screenOrientation="landscape" in manifest
I want to have it forced to portait because I'm building a camera app and it messes up the camera everytime and I want to have it like the default camera has it - no change, just the button orientation. If that makes sense.
A lot of camera apps achieve this by rotating Views and it's a good way to do it because you don't have to deal with Activity lifecycle as well as camera lifecycle. They have a locked orientation but they use accelerometer to get device rotation and then rotate Views accordingly.
Camera API gives you ability to set camera rotation as well as picture orientation. Picture orientation should be set to zero because Camera API is unreliable with this.
Use accelerometer to determine real device rotation and set EXIF rotation of the picture to a correct one.
In my android Activity I need to update the camera preview orientation and the UI according to the device Orientation. And I need all orientations for my activity namelyPortrait,Landscape,Landscape reverseandportrait reverse`.
I use the Android API demo for the camera preview. I found that when I use fullSensor for orientation setting in my AndroidManifest.xml and call the setCameraDisplayOrientation() on surfaceChanged() method of the Preview class(I am referring to the CameraPreview.java in the API demo sources) I get the desired behavior.
But there is a big delay on each orientation switch. When I set the orientation to Landscape in the manifest the preview is smooth but the UI is not updating according to the device orientation. I need the orientation to be set to Landscape and the UI to change according to all the four orientations namely Portrait up, Landscape right, Landscape left and Portrait down. What is the optimal way of achieving the same with good performance?
In android, we can set the value 0/1 to orientation Accelerometer to lock the phone at portrait mode or rotate based on sensor state. I have make vary searching on the web but i can't find what value i should set to lock the phone at landscape mode. Some one can help me?
android.provider.Settings.System.putInt( getContentResolver(),
android.provider.Settings.System.ACCELEROMETER_ROTATION,
isLocking ? 0 : 1);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
set above line after your setContentView(view); this will set you device orientation of that activity to landscape
I have an camera activity in my app, where user can make a photo. For some reasons it's fixed to landscape mode(by the screenOrientation in manifest). All works perfectly but I need to know - what screen mode on picture? User can rotate device and try to make a photo in portrait mode.
I've tried to use getRotation method but it returnes only 0 degrees, cause i'm set to portrait screenOrientation.
I want to ask - is there some ways to solve this problem?
Thanks for any help!
Use the orientation sensor, ain't as difficult as you might think.
http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/
Android phone orientation overview including compass
In my onCreate method, I'd like to detect the orientation and set an appropriate background image.
I can get the orientation like so:
Display dis = getWindowManager().getDefaultDisplay();
int orientation = dis.getOrientation();
I've tested this on both the Galaxy S and the Moment.
When I am in portrait mode, this returns a value of 0. When I am in landscape mode, this returns a value of 1.
However, the define Configuration.ORIENTATION_LANDSCAPE has a value of 2 and the define Configuration.ORIENTATION_PORTRAIT has a value of 1.
So, when I turn the phone to landscape mode, it gives me Configuration.ORIENTATION_PORTRAIT. And when I turn the phone to portrait mode, it gives me Configuration.ORIENTATION_UNDEFINED.
What is going on???
I'm using API level 7
One thing you could do is just put the landscape drawable into a /drawable-land/ folder, and Android will pull it automatically depending on the orientation. Rather than relying on that, though, you would be better off to make a landscape version of the layout under /layout-land/ that has the alternate version as its background.
Look at the answers in Check orientation on Android phone