Search code examples
androidsettingsmonkeyrunnerandroid-developer-api

MonkeyRunner script go to 'Developer options' then check 'Stay Awake' but is not recorded


I am doing a MonkeyRunner script that sets some settings in the android settings menu. The problem is that when I go to developer options, I need to check 'Stay Awake' and 'Allow mock locations' but when the script is finished these two are not checked anymore.

It seems that the device doesn't allow to change some settings through adb because when I do it manually it works.

device.touch(406, 336, "DOWN_AND_UP")

MonkeyRunner.sleep(2.0)

img = device.takeSnapshot().getSubImage((0, 300, 450, 80))

img.writeToFile(afterImg)

MonkeyRunner.sleep(2.0)

This is the part of the code that click on 'Stay Awake' and get an image of the result. The image show that the button is clicked. But after the script if I go back manualy I can see that 'Stay Awake' is unchecked.


Solution

  • The problem is coming from MonkeyRunner. I recomend to use @dtmilano tool AndroidVIewClient that is easier to use than MonkeyRunner. This tool solved my problem.