简体   繁体   中英

How to emulate step counter sensor in the Android devices?

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 .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM