我正在使用真实设备上的 Android 4.4,并希望通过 adb
设置设备方向。 我不想使用 uiautomator 来完成,因为在 uiautomator 代码终止后它不会持续存在。
我该如何做?
我正在使用真实设备上的 Android 4.4,并希望通过 adb
设置设备方向。 我不想使用 uiautomator 来完成,因为在 uiautomator 代码终止后它不会持续存在。
我该如何做?
使用 "adb shell settings" 而不是 "adb shell content" 更加简洁。它们是在向设置提供程序中放置值方面做着相同的事情。
adb shell settings put system accelerometer_rotation 0 #disable auto-rotate
adb shell settings put system user_rotation 3 #270° clockwise
accelerometer_rotation: 自动旋转,0 禁用,1 启用
user_rotation: 实际旋转,顺时针,0 0°,1 90°,2 180°,3 270°
你可能需要先关闭自动旋转:
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
旋转至横屏:
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
旋转竖屏:
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
2
和 3
分别表示倒立的纵向和反转的横向。 - Matthew Readadb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
。请注意,翻译时不得改变原文意义,并尽量简洁易懂。 - Patrick Booscontent insert --uri content://settings/system
is exactly the same thing as writing settings put system
- Zibri禁用 accelerometer_rotation
并设置 user_rotation
user_rotation 值:
0 # Protrait
1 # Landscape
2 # Protrait Reversed
3 # Landscape Reversed
加速度计旋转值:
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);
wm cmd 可用于在 adb shell 上设置用户旋转
wm help
user-rotation [free|lock] [-d DISPLAY_ID] [rotation]
Set user rotation mode and user rotation.
例子:
wm user-rotation lock 0
wm user-rotation lock 1