You might want to use this:

http://developer.android.com/reference/android/view/OrientationEventListener.html

If it doesn't exactly serve your needs, just copy the code into your own app
and tweak as desired:

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/OrientationEventListener.java

For example there is a much more specialized version of this that the window
manager uses for rotating the screen:

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/WindowOrientationListener.java

On Fri, Dec 18, 2009 at 10:50 AM, Mark Wyszomierski <mar...@gmail.com>wrote:

> Hi,
>
> I'm trying to detect landscape vs portrait orientation with the
> following:
>
>  public void onSensorChanged(SensorEvent event) {
>      float pitch = event.values[2];
>      if (pitch <= 45 && pitch >= -45) {
>         // portrait
>      }
>      else if (pitch < -45) {
>         // landscape
>      }
>      else if (pitch > 45) {
>         // landscape
>      }
>  }
>
> anyone have something more robust? It works pretty well, except if the
> phone is in a landscape orientation, and the user starts to 'flatten'
> it out, starts thinking it's in the portrait orientation again,
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to