2

I try to make live wallpaper for android, but i can't get screen rotation, because lwp - it's a service, not activity. I need integer value (0/90/180/270), not orientation (landscape/portraite), like if i'm call something like this:

((Activity) context).getResources().getConfiguration().orientation;

It is possible? I tried many ways and read many articles, but i can't do it and can't find helpful information.

Thanks!

semtiko
  • 71
  • 1
  • 1
  • 7
  • possible duplicate of [Detecting screen orientation change from service](http://stackoverflow.com/questions/6951874/detecting-screen-orientation-change-from-service) – Warpzit Nov 07 '12 at 08:54
  • Thanks, but it's like i say before - landscape/portraite orientation. I think i found solution. I check it right now and post here result. – semtiko Nov 07 '12 at 09:11

1 Answers1

4

So, i found the solution :)

public int getRotation() {
    int orientation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();

    switch (orientation) {
        case Surface.ROTATION_90:  return 90;
        case Surface.ROTATION_180: return 180;
        case Surface.ROTATION_270: return 270;
        default: return 0;
    }
}

But in my case it's little bit buggy, don't know why yet: If you place your device to 0 degrees position (portrait orientation) and rotate to 180 degrees, nothing be detected, or from 90 to 270 and versa. But if you rotate your device from 0 to 90 or 270, or from 90 to 180 and 0 and so on - all is fine (different orientations).

semtiko
  • 71
  • 1
  • 1
  • 7