Simulate ActivityRecognition events in Android emulator
Asked Answered
C

3

12

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}
Cobden answered 8/2, 2016 at 23:17 Comment(3)
I've been looking for the same thing, I hoped that doing GPS playback MIGHT kick in the IN_VEHICLE event, but sadly it does not...Ascendancy
Did you get any solution for this?Semiautomatic
Nope, didn't get one. Only solution is what @MrMagoo suggested.Cobden
U
3

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...

Undirected answered 13/4, 2016 at 19:0 Comment(1)
If you want to still discuss it, comment on the post, don't answerVenomous
D
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

Dorothydorp answered 18/9, 2017 at 19:36 Comment(0)
K
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.

Kirkham answered 15/2, 2019 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.