6

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.

Community
  • 1
  • 1
alwaysday1
  • 1,683
  • 5
  • 20
  • 36
  • Step counter is not a real hardware function as it is the GPS. Step calculation is the result of dealing with the accelerometers, so I think there's no way to simulate them. You'll have to walk... – Joaquin Iurchuk Apr 15 '15 at 14:21
  • @joaquin As far as I know, step counter is more than accelerometers nowadays, [many manufacture](http://blog.atmel.com/2013/05/13/samsungs-galaxy-s4-is-equipped-with-atmels-sensor-hub-mcu/) update their new mobile phone with sensor hub. And from Android 4.4, there are API to get the step counter data. – alwaysday1 Apr 16 '15 at 01:41

1 Answers1

1

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.

Viktor Malyi
  • 2,298
  • 2
  • 23
  • 40
  • Interesting... I'd like to remark that this method was introduced on API 19 – Joaquin Iurchuk Apr 16 '15 at 02:26
  • @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. – alwaysday1 Apr 17 '15 at 01:21
  • 1
    @liweijian just get it and then modify: mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mStepCounter = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); – Viktor Malyi Apr 17 '15 at 06:39
  • 2
    @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. – alwaysday1 Apr 17 '15 at 08:52
  • 1
    @lit2019 I am facing similar issue... Did you find a way to solve this? – Rujoota Shah Dec 02 '19 at 06:44
  • @RujootaShah Sorry, I am not working on this issue either. – alwaysday1 Dec 03 '19 at 07:38
  • Make sure to enable the android.permission.ACTIVITY_RECOGNITION in API 29. – Ludde Sep 24 '20 at 15:35
  • is 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 – hema ezzat Apr 19 '22 at 17:23