Search code examples
androidandroid-sensors

getRotation always returning 0 in Android


I'm trying to get the rotation in Android like this:

Display display = ((WindowManager)
           context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();

but rotation is always 0 despite that I'm rotating the phone in the four available positions.

Am I missing something? I'm using a real phone (Samsung Galaxy S2).


Solution

  • I didn't know that if the screen is locked the rotation is not computed, I'll try creating a WAKE_LOCK. Thanks! Guillermo.