18

I would like to test the rotation of a phone on the emulator, I see everywhere that we have to use Ctrl+F11 but it only rotates the image of the emulator and does not launch a configuration change event or redraw the activity.

Here is what I have with Ctrl+F11 :

emulator rotation

So, what do I have to use to simulate a real rotation ?

vahid abdi
  • 9,636
  • 4
  • 29
  • 35
Stephane Mathis
  • 6,542
  • 6
  • 43
  • 69

5 Answers5

50

Also you can do:

disable accelerometer controlling rotation - just do this once

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

rotate landscape:

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

rotate portrait:

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

rotate upside down landscape:

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

rotate upside down portrait:

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

If you have WRITE_SETTINGS permission you can write thru the content provider in java code as well.

Tom
  • 751
  • 5
  • 3
  • Today I try the command with latest Android SDK. The insert command change to update. And the complete command is now "./adb shell content update --uri content://settings/system --bind name:s:user_rotation --bind value:i:0". Well, just remind myself. – Charles Wu Jul 05 '15 at 08:11
5

http://developer.android.com/tools/help/emulator.html this should do it

did you also support portrait and landscape mode

KPath001
  • 870
  • 5
  • 18
  • did you set the application to work on both landscape and portrait? – KPath001 Jul 10 '12 at 19:41
  • I didn't specified it on the manifest, so that Android itself manage the rotation by destroying and recreating the activity on real devices. But it doesn't work on the amulator. – Stephane Mathis Jul 11 '12 at 09:23
  • so you want the android to recreate the destroying and recreating? Sorry, I am not positive on what your asking – KPath001 Jul 11 '12 at 11:21
  • 1
    When the phone rotates, the current activity is destroyed and the same activity is created. This is the default behavior. But in the emulator, I don't know how to do that. Ctrl+F11 only change the disposition of the emulator. You can see it on the image of my first post, the default calculator number aren't turned properly. – Stephane Mathis Jul 11 '12 at 14:42
  • Is the app supported for both landscape and portrait orientation? – KPath001 Jul 11 '12 at 17:07
  • 1
    The rotation works on my phone. I don't think that I have to allow the rotation in the manifest ? – Stephane Mathis Jul 12 '12 at 11:35
  • You have to, just to insure the same effect I believe – KPath001 Jul 12 '12 at 13:07
  • This doesn't seem answered. It doesn't appear its truly rotating like a real phone would. It doesn't destroy/create like KPath001 said. – Joel Oct 26 '12 at 01:30
  • it doesn't seemed answered to me either. I guess the resolution for now is to just not depend on the emulator for this. or, if you must, test that your app works by only doing "android:screenOrientation="landscape" in the manifest – David T. Jan 11 '13 at 17:08
4

As suggested by Nicolas Jafelle here, you can try to add the property "Keyboard Support-->yes" in the emulator settings. That helped me.

PS: it will also allow for your emulator to get input from your keyboard. See more here

Community
  • 1
  • 1
Gramotei
  • 1,524
  • 14
  • 19
  • 2
    Why is this marked as the answer??? The question is how to get a "true" rotation as what would happen on a real phone, not how to use the keyboard. – Joel Oct 26 '12 at 01:46
  • 3
    Because it is the bug in ADT and without this HW Keyboard trick it doesn't work. Even in ADT 21 that was just released. See this: http://code.google.com/p/android/issues/detail?id=34237 – Gramotei Nov 18 '12 at 09:06
  • similarly to the above solution, you can do this by adding "hw.keyboard=yes" to config.ini of the desired emulator – Amir Uval Jan 11 '13 at 17:32
  • I already had keyboard support enabled, it only change the screen of emulator, but videos, pictures,native apps doesn't get the proper rotation. – paul Oct 17 '14 at 06:54
0

this just doesn't work in 2.3 emulators, if that's what ur using

see here:

Android - Emulator in landscape mode, screen does not rotate

Community
  • 1
  • 1
David T.
  • 22,301
  • 23
  • 71
  • 123
0

I did the same thing as you and turned the "auto-rotate screen" option on in the AVD. Worked like a charm.

aclima
  • 630
  • 1
  • 11
  • 20