Mark
Mark

Reputation: 39881

Getting orientation of the device?

I have a camera preview activity, which is forced to stay in landscape mode.

Is there a way I can tell the current orientation of the phone (not the screen orientation).

Basically I want to know if the user is holding the phone in portrait mode, or in landscape mode, so I can rotate the output captured bitmap correctly (right now it just always outputs in landscape mode).

Thanks

Upvotes: 3

Views: 1151

Answers (2)

LTEHUB
LTEHUB

Reputation: 1648

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {   
            p.set("orientation", "portrait");

            ....
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {   
            p.set("orientation", "landscape");
            ....
        } 

Upvotes: 2

Erich Douglass
Erich Douglass

Reputation: 52002

You can also implement Application.onConfigurationChanged() to respond to orientation changes without having to register a SensorEventListener. It might be an easier way to go if you want to customize the layout depending on the phone orientation.

Upvotes: 0

Related Questions