10

Is there a good way to simulate a DetectedActivity.IN_VEHICLE in an Android Emulator. Currently, I'm trying to get the ActivityRecognitionApi to detect an event by sending commands via telnet.

sensor set acceleration {x}:{y}:{z}
geo fix {latitude} {longitude}
Steven Wexler
  • 16,589
  • 8
  • 53
  • 80

3 Answers3

2

Faced this same issue and got the same cricket noises you did. I partially got around the issue by refactoring such that my detected activity is processed in it's own AsyncTask class. I then wrote a series of junits that could pass in a simulate event information to this activity detection processing class. Given that android has a limit on the number of asynctask executes that can be executed per object, my junit creates runnables in a loop to interact with the activity processing class.

I also found the otto and dagger2 libraries that may work to inject events into the android bus. Still a work in progress though...

MrMagoo
  • 67
  • 1
  • 12
2

Unfortunately, GPS motion alone won't trigger activity detection. Google factors in your accelerometer and other instruments to calculate the most probable activity, and if the accelerometer shows no change, it will always just say you're STILL.

Google's official location testing docs say:

Mock locations have no effect on the activity recognition algorithm used by Location Services. To learn more about activity recognition, see the lesson Recognizing the User's Current Activity.

Unfortunately, that link has no information whatsoever about testing.

The only effective workaround I've found is to open the Virtual Sensors menu on the Android emulator and manually do something like yaw back and forth (see screenshot, just drag the "Yaw" dot back and forth and watch the phone tilt on your screen). For me this often results in a (low probability) detection of IN_VEHICLE or UNKNOWN after a while when paired with GPS mocking.

screenshot of virtual sensors with yaw

Kevin Cooper
  • 5,018
  • 4
  • 37
  • 51
0

You can use adb to connect to the shell and simulate changes manually as discussed in this answer. If you are on windows like I am, you can simply connect to the shell then enter the commands to get the pid of the service and run the kill command directly. The version of cut and sed on android are not the standard GNU versions and behave oddly enough that I haven't figured out how to do it with a single line.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
palehorse
  • 26,407
  • 4
  • 40
  • 48