Reputation: 511
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?
Upvotes: 47
Views: 107435
Reputation: 99
The newer "wm" command has a CLI linking to this setting. Below, you can use "wm" or "cmd window" to run the command, but the cmd command is the newer method for accessing service CLIs, such as activity, window, display services.
Window manager (window) commands:
help
Print this help text.
...
user-rotation [-d DISPLAY_ID] [free|lock] [rotation]
Print or set user rotation mode and user rotation.
The "free" setting takes no rotation argument.
cmd window user-rotation lock 0/1/2/3
This tells android how the rotation you want set. Some Android OSes such as custom ROMs, LineageOS have this setting built-in.
If you are still having issues with apps not rotating, or you want a more user-friendly method, you can use an app such as Rotation Control, or write your own app, to force androids rotation using an overlay (draw over other apps). In Rotation Control, after enabling the controls notification, you can enable the padlock icon to force that rotation even in unsupported apps. You can do the similar with a programmatically set forced rotation direction on an android screen overlay.
Rotation Control may not provide a method over ADB shell, but you could write an app to do that, or possibly interact with the custom notification view for ADB support.
Upvotes: 0
Reputation: 1862
wm cmd can be used to set the user rotation on adb shell
wm help
user-rotation [free|lock] [-d DISPLAY_ID] [rotation]
Set user rotation mode and user rotation.
Example:
wm user-rotation lock 0
wm user-rotation lock 1
Upvotes: 9
Reputation:
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
Upvotes: 72
Reputation: 2331
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
adb shell settings put system accelerometer_rotation 0
adb shell settings put system user_rotation 3
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);
Upvotes: 33
Reputation: 2351
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°
Upvotes: 85