使用 ADB 更改 Android 设备方向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25864385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing Android Device orientation with ADB
提问by ShibMe
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.
我在真实设备上使用 Android 4.4,我想通过adb
. 我不希望它用 uiautomator 完成,因为它不会在 uiautomator 代码终止后持续。
How can I do this?
我怎样才能做到这一点?
回答by
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
回答by wrkwrk
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 content”,而是使用“adb shell settings”更干净的方法。他们正在做同样的事情,为设置提供者赋予价值。
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°
accelerometer_rotation: auto-rotation, 0 disable, 1 enable
user_rotation: actual rotation, clockwise, 0 0°, 1 90°, 2 180°, 3 270°
回答by Benny
Disable accelerometer_rotation
and set the user_rotation
禁用accelerometer_rotation
并设置user_rotation
user_rotation Values:
user_rotation Values:
0 # Protrait
1 # Landscape
2 # Protrait Reversed
3 # Landscape Reversed
accelerometer_rotation Values:
accelerometer_rotation Values:
0 # Stay in the current rotation
1 # Rotate the content of the screen
Example using adb:
使用 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);