Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate ActivityRecognition events in Android emulator

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}
like image 636
Steven Wexler Avatar asked Feb 08 '16 23:02

Steven Wexler


2 Answers

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

like image 161
MrMagoo Avatar answered Oct 16 '22 14:10

MrMagoo


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

like image 32
Kevin Cooper Avatar answered Oct 16 '22 14:10

Kevin Cooper