The other apps that you reference do something different to what you might be expecting. They enable screen rotation based on the device's accelerometer; that is, the user rotates the device and the orientation changes. They do not set a specific orientation for any application. Note that if you disable automatic rotation whilst in landscape mode, the orientation typically returns to portrait.
I have done the same as these other applications before. Unfortunately it's proprietary commercial code that I'm not in a position to share.
There are two components to the approach:
- Detect when the foreground application is the target app
- Change the system-wide preference for display orientation
Obviously you have to do the reverse too, i.e. change it back afterwards.
There are some examples of piece 1 elsewhere on SO. In my case I wrote a service that continuously polled to see what the foreground app is (because there are no relevant system events to inform of app change). It's not a trivial undertaking but it can be done.
The relevant setting for piece 2 is Settings.System.ACCELEROMETER_ROTATION
. I think you can write that with an ordinary app permission on all versions. The code snippet for that is below:
Settings.System.putInt(
app.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION,
orientationEnabled ? 1 : 0
);
Note also that it is possible to write an application that will ignore the system's screen rotation; i.e. will stay locked in whatever orientation it was designed for. It's not common though.