I have trying following code but it displays error message:
An unknown server-side error occurred while processing the command.
(WARNING: The server did not provide any stacktrace information)
There seems to be a solution to the
"Set the orientation, but app refused to rotate." error message. Your problem could be related to the fact that the app relies on the sensor to do rotation and doesn't allow the user to set it. This was the case for "maxski" at least: https://discuss.appium.io/t/android-set-the-orientation-but-app-refused-to-rotate/3200/3
"The problem was in Android app code. Devs should set orientation reliance to user not to censor."