UNSTOPP4BLE

How to use ADB commands in order to rotate a device's screen


Tutorial overview

In this tutorial, I'll show you how to use ADB commands in order to rotate an Android device's screen.
Bear in mind that you should know how to use ADB through a terminal software (Windows' CMD, Windows PowerShell...). If not, you can look forward this tutorial that explains how to use it.

There are two parts in this tutorial; the first part covers the screen rotation by an user input, and the second part covers the screen rotation by the accelerometer.

Prerequisites

Tutorial

Explanation of how we can do this by an user input

In order to rotate a device's screen through an ADB command (given that there isn't a window manager command which can accomplish that), we must do it through the system settings. so it'd look like this :

adb shell content insert --uri content://settings/system

For now we only have a small part of the final code; this part is useful to set the path of the system settings. Now we have to bind the function that allows to make a rotation from the user side and then we will set the value for the rotation.
Binding the user rotate function :

adb shell content insert --uri content://settings/system --bind name:s:user_rotation

Now we have to set (through --bind) the wanted rotation. In order to accomplish that we have to use values; there are 4 values:

The final line looks like this :

adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0

Here we're putting the screen in portrait mode since the i value is equal to 0.

Practice

First of all, you must open ADB, once you're in the terminal software (and once you're obviously connected to your device), you have to write the line of code below and press enter.

adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0 ADB rotation

Make sure to modify the value according to your needs ! :

Your device's screen is now rotated !

Rotating the screen by the accelerometer sensor

In this second part, we will re-use the same line of code but we will modify it a little bit (by adding the sensor input) so that the screen can turn according to the accelerometer. We can disable and enable the auto-rotation just by changing the value from 0 to 1.

adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0

The code above disables the auto-rotation. If you want to enable it, you just have to change the value from 0 to 1.

Conclusion

This is the end of the tutorial, I hope it has been useful and helpful. If you want to see more tutorials related to technology and IT, you can just click here



Tell us what do you think about this tutorial :