40

I'm using Android 4.4 on a real device and I want to set the device orientation via adb. I don't want it done with uiautomator since it won't last after the termination of the uiautomator code.

How can I do this?

1

4 Answers 4

74

Instead of using "adb shell content", there's a more clean way by using "adb shell settings". They are doing the same thing, put value to settings provider.

adb shell settings put system accelerometer_rotation 0  #disable auto-rotate
adb shell settings put system user_rotation 3  #270° clockwise
  • accelerometer_rotation: auto-rotation, 0 disable, 1 enable
  • user_rotation: actual rotation, clockwise, 0 0°, 1 90°, 2 180°, 3 270°
0
72

You may first need to turn off the automatic rotation:

adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0

Rotate to landscape:

adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1

Rotate portrait:

adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
5
  • 3
    You can also use 2 and 3 for upside-down portrait and reverse landscape respectively. Feb 18, 2015 at 17:54
  • 9
    First you have to run adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0 to turn off the automatic rotation Mar 17, 2015 at 6:16
  • 1
    How do I avoid turning off the automatic rotation? and how do I get and restore its original value? Sep 3, 2016 at 10:32
  • Worked like a charm, disabling automatic rotation was important.
    – vishalm
    Oct 13, 2016 at 19:52
  • content insert --uri content://settings/system is exactly the same thing as writing settings put system
    – Zibri
    Nov 10, 2022 at 20:59
31

Disable accelerometer_rotation and set the user_rotation


user_rotation Values:
0           # Protrait 
1           # Landscape
2           # Protrait Reversed
3           # Landscape Reversed
accelerometer_rotation Values:
0           # Stay in the current rotation
1           # Rotate the content of the screen

Example using adb:

adb shell settings put system accelerometer_rotation 0
adb shell settings put system user_rotation 3

Example programmatically:

import android.provider.Settings;

// You can get ContentResolver from the Context
Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, 3);
0
6

wm cmd can be used to set the user rotation on adb shell

wm help
set-user-rotation [free|lock] [-d DISPLAY_ID] [rotation]
Set user rotation mode and user rotation.

Example:

wm set-user-rotation lock 0
wm set-user-rotation lock 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.