4

For my Android app, the value returned for activity.getResources().getConfiguration().orientation is always 1 (ORIENTATION_PORTRAIT), even when the device is in landscape mode. This is happening specifically on Samsung galaxy devices. This is causing my fragment to use the portrait layout instead of the landscape layout present in the project. Is there a different way to check the orientation on Samsung devices? Is anyone else facing the same issue?

    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);

    // Get device orientation
    Configuration config = activity.getResources().getConfiguration();
    mOrientation = config.orientation;
2

1 Answer 1

1

You are not the first to complain about this flaw on some Samsung phones: control orientation by sensor on Samsung devices. If you don't care about the case of SCREEN_ORIENTATION_REVERSE_PORTRAIT, maybe, for you SCREEN_ORIENTATION_SENSOR will work better than SCREEN_ORIENTATION_FULL_SENSOR.

I am not surprised that this manufacturer did something that doesn't work for you as expected. I believe that you can still use the OrientationListener to derive the true device orientation from accelerometer, like in How to detect my screen orientation in portrait locked screen in android? .

Sign up to request clarification or add additional context in comments.

4 Comments

I tried to use SCREEN_ORIENTATION_SENSOR but that didn't work either. When my device was in landscape mode, getResources().getConfiguration().orientation was still returning 1 (ORIENTATION_PORTRAIT).
So, the OrientationListener is your way
Yes, definitely I can try that solution but ideally what I want is that when I inflate a layout, it should automatically detect which layout folder to use (portrait or landscape). Setting the correct sensor would be really useful in that case. That is why I was trying to set the right sensor but not able to do so till now.
My preference has always been to keep camera preview in one predefined orientation, probably landscape, like all preinstalled camera apps. The motivation is that I want to keep the viewfinder smooth even when the device is rotated. I still must keep track of orientation, at least to set correct EXIF rotation flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.