通过 ADB 连接时强制屏幕方向

问题描述 投票:0回答:2

每当我通过 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 命令,设备就会设置为自动旋转。我如何将默认设备方向设置为纵向,或者以其他方式解决问题?

android adb
2个回答
0
投票
device.shell('settings put system user_rotation 0')

device.shell('settings put system accelerometer_rotation 0')

您可以通过

user_rotation
选择与所需方向相对应的值(0为纵向,1为横向)

您可以更改

accelerometer_rotation
来禁用或启用旋转(0 保持当前状态,1 旋转屏幕)


0
投票

禁用自动旋转

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
© www.soinside.com 2019 - 2024. All rights reserved.