Reputation: 203
To get orientation, I have tried the below codes. But I don't get the desired output.
int rotation = getWindowManager().getDefaultDisplay().getRotation();
and
Display display = ((WindowManager)this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
I have tried this both of code and rotate the device every angle but always get rotation value 0.
Then I have tried this below code
int rotation = this.getResources().getConfiguration().orientation;
But now I am always getting rotation value 1. How I will get different value of rotation for Natural orientation, Landscape left, Upside down, Landscape right?
Upvotes: 2
Views: 292
Reputation: 352
You can use getRequestedOrientation()
and it will return one of these values.
Hope this helps !
Upvotes: 1