How to emulate step counter sensor in the Android devices?
14,709
It's pretty easy since in reality this sensor returns a float number describing the number of steps taken by the user since the last reboot while activated.
So that the easiest implementation will include a method which generates just a random float within some realistic constraints (between 1 and 9999 steps):
public float generateStepsCount(){
float minVal = 1.0f;
float maxVal = 9999.0f;
Random rand = new Random();
return rand.nextFloat() * (maxVal - minVal) + minVal;
}
PS: TYPE_STEP_COUNTER has been there since API 19.
Author by
alwaysday1
Updated on June 20, 2022Comments
-
alwaysday1 about 2 years
I want to emulate user's walking and count their steps for auto testing.
I tried to search for the solution, but only found simulate the location.
-
Joaquin Iurchuk about 9 yearsInteresting... I'd like to remark that this method was introduced on API 19
-
alwaysday1 about 9 years@ViktorMalyi thanks for your answer. I know we can mock the counter sensor's return number. But what I need is I want to change the value which was stored in the
real
sensor devices. -
Viktor Malyi about 9 years@liweijian just get it and then modify: mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mStepCounter = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
-
alwaysday1 about 9 years@ViktorMalyi Actually what I need is to simulate the users' walking, and send some signals to the sensor hub and tell it to update the steps' count.
-
Rujoota Shah over 4 years@lit2019 I am facing similar issue... Did you find a way to solve this?
-
alwaysday1 over 4 years@RujootaShah Sorry, I am not working on this issue either.
-
Ludde almost 4 yearsMake sure to enable the android.permission.ACTIVITY_RECOGNITION in API 29.
-
hema ezzat about 2 yearsis there an actual repo or a software that already simulate? I found a repo called sensorsimulator on github but it was from 10 years ago and it has so many issues