User7723337
User7723337

Reputation: 12018

Way to find device orientation change after calling `setRequestedOrientation`

Is there any way in Android to know device orientation change after we call setRequestedOrientation, I have tried following ways.

  1. getResources().getConfiguration().orientation
  2. OrientationEventListener
  3. Display getOrient = getWindowManager().getDefaultDisplay().getRotation();

But all the above methods are give same values even after changing the device orientation.
Can someone please suggest some way by which we can find the device orientation change after we call setRequestedOrientation.

Upvotes: 1

Views: 453

Answers (2)

Marcelo Idemax
Marcelo Idemax

Reputation: 2810

Might be a workaround: Handle onOrientationChanged degree from OrientationEventListener added to currente context. For example:

final OrientationEventListener orientationEventListener = new OrientationEventListener( getApplicationContext() ) {

    @Override
    public void onOrientationChanged( final int orientation ) {
        Log.i( "orientation_test", "orientation: " + orientation );
    }
};

orientationEventListener.enable();

Add and enable it at onResume and disable at onPause of Activity for example.

Upvotes: 3

arnefm
arnefm

Reputation: 1008

This should work:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
    // Do something
else
    // Do something else

Upvotes: -1

Related Questions