I have had a device, which apparently had something broken with the orientation, because after reboot, for about an hour, it would rotate the screen in response to a change of orientation - and then it would stop responding, both on the "desktop" level and application level.
So, I found Change Screen Orientation programmatically using a Button, and I assumed I can create a "icon button only" app, which when pressed, would not run a new application, but instead just try to change the orientation.
The skeleton for the "icon/button-only" app is a copy of Lock screen (it.reyboz.screenlock). I posted this project on a gist - but since it is hard to have folders (and binary files) by default in a gist, this is the procedure you can use to get the code:
git clone https://gist.github.com/e6422677cababc17526d0cb57aceb76a.git dl_archive_git
cd dl_archive_git
bash run-me-to-unpack.sh
# check upacked dir:
tree rotate-btn-droid
cd rotate-btn-droid/
# change your SDK path (ASDKPATH) in buildme.sh, and then:
bash buildme.sh
# if your java install is not in the path, then call the last command with JAVA_HOME prepended:
# JAVA_HOME=/path/to/jdkXXX bash buildme.sh
Basically, I'm just trying to do the following in MainActivity.java
:
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
// OR: orientation = getRequestedOrientation(); // inside an Activity
switch(orientation) {
case Configuration.ORIENTATION_PORTRAIT:
setRequestedOrientation (Build.VERSION.SDK_INT < 9 ?
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
break;
case Configuration.ORIENTATION_LANDSCAPE:
setRequestedOrientation (Build.VERSION.SDK_INT < 9 ?
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
break;
}
... however, nothing happens when I click the app icon and run this code.
So, my question is - is it possible in principle to force a change of the device orientation on a "desktop" level? If so, is it dependent on Android version (possibly vendor branded) or not - and how?