Android TYPE_STEP_DETECTOR on screen off

Hello I am developing a pedometer app that uses the TYPE_STEP_DETECTOR sensor type for Android KitKat. Everything seems to work fine until I turn off the screen or lock my phone. I found that it doesn't fire an event when the screen is off.

I know the TYPE_STEP_COUNTER option, but I'm not too keen on making daily contributions to my initial account at the start of the day. I would prefer the event to be fired when the step was detected, then add "1" to the day step count.

Has anyone successfully used TYPE_STEP_DETECTOR on a service running in the background even when the screen is off?

code in sensorEventListener:

if (source.equals(countSensor)) { // data came from step detector 
    // stepcount from step counter event.values[0]; 
    curStepCount = (int) event.values[0]; 
    stepcount += curStepCount;

      

after you go back to the screen, I only go back to 1 step added to the bill.

+1


source to share


1 answer


The problem is energy consumption. If the phone wakes up the app processor every time a step occurs, it will consume more power and may result in poor battery life. From your phone, the manufacturer has decided NOT to support a "wake up" version of the sensor, which would turn on the phone when a step is detected.

To save energy, the counting is best done in some type of motion coprocessor, usually an ARM Cortex M4 processor, which uses very little power. This was introduced in the Nexus 5 . If you are accessing the TYPE_STEP_COUNTER sensor , this should provide what you need.

Finally, the Android specification allows someone to install a "wake up" sensor, ie. something that turns on the application processor to signal your application and let you count it. In this particular case, you shouldn't do this because of the big impact on battery life.



See here from line 449 onwards, note that it allows "wake up and not wake up": http://source.android.com/devices/halref/sensors_8h_source.html

/*
 * SENSOR_TYPE_STEP_DETECTOR
 * reporting-mode: special
 *
 * A sensor of this type triggers an event each time a step is taken
 * by the user. The only allowed value to return is 1.0 and an event
 * is generated for each step.
 *
 * Both wake-up and non wake-up versions are useful.
 */

#define SENSOR_TYPE_STEP_DETECTOR                   (18)
#define SENSOR_STRING_TYPE_STEP_DETECTOR            "android.sensor.step_detector"

      

+1


source







All Articles