I'm working on an app/game that should switch between portrait
and reversePortrait
in multiplayer mode. (Mainly because each player might use the keyboard on his/her turn while the device is fixed on the table between them.)
My app works fine when the auto-rotate is ON.. But the reversePortrait
orientation is NEVER achievable when the device auto-rotate is OFF!
What I did so far is that I've set the orientation in the Manifest
file:
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
then I change the orientation programmatically in runtime by calling this method when needed:
public void rotateScreen(boolean reverse){
if (reverse) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
But that still doesn't force to reversePortrait
orientation if the device auto-rotation is OFF.
I also tried theonConfigurationChanged()
method, but it didn't work as well. I think it only gets called AFTER changing the orientation already, not before!
I even tried screenOrientation="reversePortrait"
in the Manifest
file, but even that is ineffective when auto-rotation is OFF.