Unable to rotate the device screen to LANDSCAPE View using appium for android native app ,but manually able to rotate the screen

I am automating android native app and I have a scenario to test the data in landscape and portrait views, but I am not able to rotate the screen to landscape view and I am using below code.

orientation as parameter("“LANDSCAPE”","“PORTRAIT”")
public void rotateScreen(ScreenOrientation orientation)
{
try{
((Rotatable)getDriver()).rotate(orientation);
}catch(Exception e){
LOGGER.info("“Exception in rotateScreen()”" + e);
}
}

I am getting exception when executing above code.

please help me to resolve this issue.

Thanks in advance

Try with mobiledriver instead of Rotatable.

Hi,

I tried with mobileDriver also, still I am getting exception and not able to rotate the screen to LANDSCAPE.

In both emulators and devices , we are getting this exception

Here is the exception message:

alling AppiumDriver.setOrientation() with args: [“LANDSCAPE”,“c1524811-50d1-44fa-8856-770bbb44a0d8”]
[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“orientation”,“params”:{“orientation”:“LANDSCAPE”}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“orientation”,“params”:{“orientation”:“LANDSCAPE”}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: orientation
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Desired orientation: LANDSCAPE
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Current rotation: ROTATION_0
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:13,“value”:“Set the orientation, but app refused to rotate.”}

Please help me to resolve this issue.

Thanks in Advance,