Sample Header Ad - 728x90

How to set emulator sensor values programmatically?

1 vote
0 answers
787 views
I'm looking for a way to set the x, y, and z values for the accelerometer sensor on an android emulator for tests using espresso. My test requires that the device be positioned in a specific way and I am aware that the android emulator has extended controls to modify the rotation and movement of the virtual sensors. However, I am looking for a way to do this automatically without needing to use the extended controls or physically moving an actual device. I have successfully modified the virtual sensors through the emulator console when connecting to the emulator via telnet; however, I haven't found a way to achieve this programmatically. To do this via telnet, I first needed to enter an authentication token, then, I used the following console command
set acceleration x:y:z
. I have previously used
shell dumpsys battery set level
to modify the battery level of the device and I was wondering if there was a similar command to modify the x, y, and z components of the accelerometer. Is there a way to achieve my goal programmatically, or will I need to aim for manually manipulating either the emulated or physical device during tests?
Asked by Jose Jaime (11 rep)
Feb 4, 2021, 09:40 PM
Last activity: Jun 12, 2022, 02:42 PM