I'm trying to get Device orientation but defaultDisplay.orinentation is deprecated, What are the alternatives for this?
Please note I do not need to use orientationEventListener for this because that will trigger only when device orientation changes.
CodePudding user response:
You can use this: https://developer.android.com/reference/android/app/Activity#getRequestedOrientation()
Activity instance is required
CodePudding user response:
Look at the docs. It tells you what it was deprecated in favor of. In this case, defaultDisplay was deprecated in favor of Context.getDisplay(). GetOrientation was deprecated in favor of getRotation()
CodePudding user response:
here is an alternative way
int orientation = this.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
// the new mode is portrate
} else {
// the new mode is landscape
}