Auto screen orientation changes with respect to time intervals

1.6k views Asked by At

I wanted to rotate the screen orientations i.e from landscape -> patriot and vice verse for every 500 ms(This is on real device(not on emulator)). Is there any shell command where we can rotate the current screen orientation? This is not corresponding to any of the app. I just want to rotate the screen in all available directions with irrespective to current activity

I've checked with adb shell to change the screen to landscape:

service call window 18 i32 1

change the screen to portrait:

service call window 18 i32 0

But these are not working on real device.. Can any one please provide a better solution to do this, would really helpful for me.

Atleast share/point me to any available scripts/apks that will do this auto orientations.

Thanks in advance

2

There are 2 answers

4
tozka On

Well adb shell is still a shell (if a bit cut down)

You can do this:

sw=1;
while true; do
    [[ "$sw" = 1 ]] && sw=0 || sw=1;
    service call window 18 i32 $sw;
    sleep 1
done;

And this is the one line version of it (in case you can not write it in file)

sw=1; while true; do [[ "$sw" = 1 ]] && sw=0 || sw=1; service call window 18 i32 $sw; sleep 1; done;

This will switch orientation every second (I don't think sleep works with less than seconds)

0
lmaayanl On

I came across the same problem, and found a solution in here.

briefly, that's what you have to do:

First disable the auto rotation by using the following command:

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

and to rotate:

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

for landscape replace x (in the end of the line) with 1 and for portrait with 0, and the code from the previous comment should work just fine :)