I'm trying to get the current orientation of an activity and lock it like this but it just goes to portrait even when opened in landscape mode.
//getRequestedOrientation();
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LOCKED);
Thanks
I'm trying to get the current orientation of an activity and lock it like this but it just goes to portrait even when opened in landscape mode.
//getRequestedOrientation();
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LOCKED);
Thanks
You have screen orientation locked, it will show your app in portrait mode, you should use screen orientation sensor.
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Edit.
int str = 0;
try {
str = Settings.System.getInt(contexto.getContentResolver(),Settings.System.ACCELEROMETER_ROTATION);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
if(str!=0)
{
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
Also check this link, I think it can help you.
This seems to do the trick:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);