每当我通过 ADB 连接到任何设备时,屏幕方向都会设置为自动旋转。
adb = Client(host="127.0.0.1", port=5037)
devices = adb.devices()
adb.remote_connect("192.168.178.31", 5555)
device = adb.device("192.168.178.31:5555")
device.shell('input touchscreen tap 537 869')
因此,只要我运行 shell 命令,设备就会设置为自动旋转。我如何将默认设备方向设置为纵向,或者以其他方式解决问题?
device.shell('settings put system user_rotation 0')
device.shell('settings put system accelerometer_rotation 0')
您可以通过
user_rotation
选择与所需方向相对应的值(0为纵向,1为横向)
您可以更改
accelerometer_rotation
来禁用或启用旋转(0 保持当前状态,1 旋转屏幕)
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
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:2
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:3
这就是 Android 设置向导中的工作原理。在设置过程中自动旋转设置为禁用(0),直到我们按“完成”,然后自动旋转再次设置为活动。
adb shell settings
不会在“飞行”中工作,所以最好使用 adb shell content
来做这样的事情:
Utils : backupDefaultScreenOrientation, set auto rotate 0
07-16 13:28:36:953 Utils : restoreDefaultScreenOrientation, set auto rotate 1