Check a screen orientation when it's fixed by manifest file - android

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

Related

Allow user to Landscape Right and Left without using Auto Rotation

I tried using the SystemChrome to change the orientation and it works for Lock ScreenOrientation. But As i provided two orientation. Application takes the first orientation until user start the Auto Orientation from Setting.
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
Is it possible to allow user to change the orientation without using Auto-Orientation Service ?
It works only with android devices:
add attribute to main activity in AndroidManifest.xml
<activity
android:screenOrientation="sensorLandscape"
...
and now screen retains landscape orientation, but can be either normal or reverse landscape based on the device sensor. The sensor is used even if the user has locked sensor-based rotation.
Hey #Ashish I found one link for you for Orientation functionality and Concept
SystemChrome.setPreferredOrientation
The idea here is using make a sensor plugin to take only the screen orientation landscape info. Sensor will work even user locks the orientation.
https://www.techrepublic.com/article/pro-tip-use-android-sensors-to-detect-orientation-changes/
From the flutter site, put a listener somewhere and take a rotation programmatically by setPreferredOrientations method.
https://master-api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html

Get android device orientation even when autoRotation is turned off

I have an android app in which the screen orientation is set to portrait in manifest file.
It uses a custom camera in b/w , to take a photo and I need to save the photo.
Before I save the image I have to rotate the image depending on how the user is holding the camera, so that the image gets saved in the right orientation.
So, is there any way by which I can get the device orientation even when my app is running in portrait mode and android "auto-rotation" feature is ON.
How can I achieve this?
You should do the rotation depending on the orientation information within the image, not depending on the device orientation.
Here is some more information on how to determine the rotation.
Since this does not help, have you tried hackpod's answer here:
getResources().getConfiguration().orientation
To get current device orientation try this:
getWindowManager().getDefaultDisplay().getRotation();
Simply check, the height and width of the image. If the height is less than your width, it means the user was holding the phone horizontally, so you have to rotate it.
I am currently using android orientation sensor to solve this problem and its working perfectly. Till someone gives a better working method , am accepting this as answer for other who have the same question.

How to force change layouts in Android

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.

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!

Android activity rotation locked in manifest, but need to grab the orientation event

I am designing a application that uses the camera. I want it locked it landscape mode and just have the pictures(for example, a handle to change between camera and video) rotate. I don't want to launch onCreate() again. This is so the camera/video logo does not appear sideways on the screen.
I have put this in the manifest:
android:screenOrientation="landscape"
This keeps the screen from turning. However, I can't seem to figure out how I get the event that tells me when turn the images. I have seen camera apps do this.
Thanks!
If you've locked your activity using manifest, the only workable solution to track orientation I saw was using OrientationEventListener.
You'll need to convert degrees to correct orientation yourself. But that is relatively easy task.

Categories

Resources