1

I would like to get actual orientation of my DEVICE. I dont want to get layout orentation like this:

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
return display.getOrientation();

I want to get physical device orientation. Is there any way to get that in android?

PedroHawk
  • 622
  • 5
  • 19
Sayaki
  • 769
  • 14
  • 36
  • 1
    http://stackoverflow.com/questions/10380989/how-do-i-get-the-current-orientation-activityinfo-screen-orientation-of-an-a – Illegal Argument Jun 25 '14 at 10:09
  • 1
    Try this way in this answer [http://stackoverflow.com/questions/22456024/how-to-get-the-android-devices-physical-orientation-in-degrees][1] [1]: http://stackoverflow.com/questions/22456024/how-to-get-the-android-devices-physical-orientation-in-degrees – QArea Jul 18 '14 at 11:58

1 Answers1

2

Use Orientation change listener

OrientationEventListener mOrientatinChangeListener = new OrientationEventListener(getApplicationContext(), SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int orientation) {
            // Here you will get the actual orientation 
        }

    };


protected void onStart() {
    super.onStart();

    // Activate the Orientation change listener
    mOrientatinChangeListener.enable();     
}

Note : If you are expecting a 3 dimensional orientation from gyroscope/ accellerometer then Using Android gyroscope instead of accelerometer. I find lots of bits and pieces, but no complete code

Community
  • 1
  • 1
naveejr
  • 735
  • 1
  • 15
  • 31