How to emulate step counter sensor in the Android devices?

hellotli picture hellotli · Apr 15, 2015 · Viewed 13.5k times · Source

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.

Answer

Viktor Malyi picture Viktor Malyi · Apr 15, 2015

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.