Reputation: 12018
Is there any way in Android to know device orientation change after we call setRequestedOrientation
, I have tried following ways.
getResources().getConfiguration().orientation
OrientationEventListener
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
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
Reputation: 1008
This should work:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
// Do something
else
// Do something else
Upvotes: -1