How to Change Android Device Orientation Using ADB

How to Change Android Device Orientation Using ADB

10 November 2024 Stephan Petzl Leave a comment Tech-Help

Changing the orientation of an Android device programmatically can be crucial for testing and development purposes, especially when you need to simulate different device orientations without relying on physical manipulation. Here’s a guide on how you can achieve this using ADB (Android Debug Bridge) commands.

Setting Device Orientation

One efficient way to change the orientation is by using the adb shell settings command. This method directly interacts with the system settings to disable auto-rotation and set a specific user rotation.

Disable Auto-Rotation

  • Command: adb shell settings put system accelerometer_rotation 0
  • Description: This command disables the automatic rotation feature of your device.

Set User Rotation

  • Command: adb shell settings put system user_rotation [value]
  • Description: This command sets the orientation of the device. The rotation values are as follows:
    • 0: 0° (Portrait)
    • 1: 90° (Landscape)
    • 2: 180° (Reverse Portrait)
    • 3: 270° (Reverse Landscape)

Using WM Command for Rotation

Another method for setting device orientation is through the wm command, which provides additional flexibility and is particularly useful for newer Android versions.

Lock User Rotation

  • Command: wm user-rotation lock [value]
  • Description: This command locks the device orientation to a specific angle, similar to the settings command but with more granularity for display management.

Advanced Testing with Repeato

For developers looking to automate testing across various device orientations, Repeato offers a robust solution. As a no-code test automation tool for iOS and Android, Repeato allows you to create, run, and maintain automated tests efficiently. Utilizing computer vision and AI, it enables quick editing and execution of tests.

Repeato integrates ADB commands seamlessly, allowing you to execute these commands through script steps, ensuring precise timing and execution sequence. This feature is particularly beneficial when testing app behavior under different screen orientations, enhancing the reliability and coverage of your automated test scenarios.

For more information on setting up and running tests with Repeato, visit our documentation.

Like this article? there’s more where that came from!