The same problem for me with your second adaptation, and I used a workaround for the code that you are not looking for.
I added 4 value folders under the res folder. "values", "values-v11", "values-v14" and "values-sw720dp"
Folders of all values ββhave "integers.xml".
"values" and "values-v14" have a value of 1, which is a portrait orientation,
<integer name="portrait_if_not_tablet">1</integer> .
"values-v11" and "values-sw720dp" have a value of 2, which is the user's orientation;
<integer name="portrait_if_not_tablet">2</integer> .
And in the manifest file, activity has a property like:
android:screenOrientation="@integer/portrait_if_not_tablet" .
All "values", "values-v11", "values-v14" work as expected, but "values-sw720dp"!
During debugging, I realized that the portrait_if_not_tablet value occurs as expected on the sw720dp device (with API 16) using getResources (). getInteger (R.integer.portrait_if_not_tablet), but when I checked the current orientation value with getRequestedOrientation () I got a different value.
int requestedOrientation = getResources().getInteger(R.integer.portrait_if_not_tablet); int currentOrientation = getRequestedOrientation(); if (currentOrientation != requestedOrientation) { setRequestedOrientation(requestedOrientation); }
So, I used the code block for the onCreate method for my actions to solve this problem.
source share