androidadb

Forced screen orientation when connecting via ADB


Whenever i connect to any device via ADB, the screen orientation is set to auto rotate.

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')

So as soon as i would run the shell command, the device would be set to auto rotate. How would i either set the default device orientation to portrait, or fix the problem otherwise?


Solution

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

    You can choose the value that corresponds to the desired orientation by user_rotation (0 for portrait, 1 for landscape)

    Instead of you can change accelerometer_rotation for disable or enable rotation (0 stay current, 1 rotate screen)