As you can see Youtube app for Android that can rotate screen from portrait to landscape even when option "Auto-rotate screen" is disable in setting. How can i do same it? Thank all guys!
5 Answers
Use - ActivityInfo.SCREEN_ORIENTATION_SENSOR
if you want to rotate screen irrespective of user's choice else use ActivityInfo.SCREEN_ORIENTATION_USER
. This will only rotate screen if its turned on.

- 15,088
- 1
- 48
- 50
Use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR), it will disregard the auto rotate option and just rotate whenever your device is rotated.

- 2,287
- 3
- 34
- 49
You can also use
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//This is the default value
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled)
{
Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
-
if Auto-rotate screen" was disabled in setting, I don't know when my phone rotate. Are you understand my objective? – tungdx Jan 24 '13 at 10:15
-
Thank Helios-Ignite, i can set Orientation of Android device when use your method "setAutoOrientationEnabled" above. Thank you again! – tungdx Jan 24 '13 at 10:31
As it's shown here http://developer.android.com/guide/topics/sensors/sensors_overview.html you can register your own sensor (TYPE_ACCELEROMETER
in this case) and then listen on it's events.
When you calculate that phone orientation has been changed you should programmatically change layout orientation then.

- 30,639
- 18
- 84
- 159

- 14,592
- 14
- 66
- 90
-
[link](http://www.vogella.com/articles/AndroidSensor/article.html) and [link](http://www.slideshare.net/info_zybotech/android-accelerometer-sensor-tutorial) - here are the best tutorials in this topic which I know. – Kamil Lelonek Jan 24 '13 at 10:28
Use this in onCreate of that activity you want to be able to rotate the screen:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
It won't affect other activities or the whole device settings.
I have tried that. It works.

- 3,033
- 5
- 36
- 61