0

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

msk
  • 135
  • 2
  • 13
  • using thread you have to change orientation in specific time interval setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); and setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); – Parag Ghetiya Oct 13 '12 at 12:03
  • can we do this as another apk which will rotates the screen orientations automatically based upon the given time interval? – msk Oct 13 '12 at 19:36

2 Answers2

0

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)

tozka
  • 3,211
  • 19
  • 23
  • I've tried this trick, But still no luck :( .. After invoking the command nothing is happening on the real device.. I have debugged almost all what i can do.. do we explicitly do any native code which will handle this type of scenarios? – msk Oct 13 '12 at 16:01
  • this what i am seeing from console – msk Oct 13 '12 at 19:36
  • root@android:/ # service call window 18 i32 0 service call window 18 i32 0 Result: Parcel(fffffffc ffffffff '........') – msk Oct 13 '12 at 19:37
  • I've tried it on another emulator on windows machine and see the Window Manager Crash is happening due to java.lang.NullPointerException.. Is there any env setup/settings to do this? – msk Oct 15 '12 at 08:01
0

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

Community
  • 1
  • 1
lmaayanl
  • 378
  • 1
  • 2
  • 15