1

Is there any approach to get screen orientation, when device is blocked and screen is turned off? I tried

getResources().getConfiguration().orientation

and

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

but both of them return "portrait" and "0" respectively when sreen is off, no matter what the actual orientation is.

Maxim Efimov
  • 2,747
  • 1
  • 19
  • 25

1 Answers1

1

I do not understand what you mean by "blocked", but if the screen is turned off, the OS seems to set the orientation to Portrait. You can test this by getting an app to a landscape mode, lay it flat down and turning off the screen. When you turn on the screen again, the app is now in portrait mode. If the device is not flat you can visibly see the orientation changes from portrait to landscape.

Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
  • I mean "screen off". So, it is not possible to get the true orientation if the screen is turned off? I thought about sensors etc. – Maxim Efimov Mar 15 '13 at 04:20
  • Do you mean by "true orientation" the orientation of the device, independent of applications? – Hoan Nguyen Mar 15 '13 at 04:23
  • Yes I do. It's important for my app. – Maxim Efimov Mar 15 '13 at 04:26
  • You can certainly use sensor, but portrait and landscape are relative. I can show you how to get the device rotation from sensor. – Hoan Nguyen Mar 15 '13 at 04:29
  • It would be very helpfull! Please, explain. – Maxim Efimov Mar 15 '13 at 04:32
  • Look at my answer at http://stackoverflow.com/questions/11175599/how-to-measure-the-tilt-of-the-phone-in-xy-plane-using-accelerometer-in-android/15149421#15149421 It used to be that android would change orientation for example Portrait to Landscape if the rotation as calculate from the link above is about 60 degrees. In another word, change of orientation occurs if change in rotation is about 60. But not any more in new version. You have to play around to adapt to your situation. – Hoan Nguyen Mar 15 '13 at 04:40