Hello I'm developing a pedometer application that uses the TYPE_STEP_DETECTOR sensor type for Android KitKat, All seems to work fine until I turn the screen off or lock my phone, I find that it doesn't fire an event when the screen is off.
I am aware of the TYPE_STEP_COUNTER variant but I'm not too keen on keeping tabs on the starting count at the start of the day everyday. I would much rather have the event fired when a step is detected and then add "1" to the day's step count.
Has anyone successfully used the TYPE_STEP_DETECTOR in a service running in the background even when the screen is turned off?
code in sensorEventListener is:
if (source.equals(countSensor)) { // data came from step detector
// stepcount from step counter event.values[0];
curStepCount = (int) event.values[0];
stepcount += curStepCount;
after turning the screen back on I end up with only 1 step added to the count.
The problem is power consumption. If the phone wakes up the application processor every time a step occurred, it will draw more power and could lead to poor battery life. With your phone, the manufacturer has made a decision NOT to support a "wake-up" version of the sensor that would turn the phone on when a step is detected.
To conserve power, the counting is best done in a motion co-processor of some kind, typically a ARM Cortex M4 processor that uses very little power. This was introduced in the Nexus 5. If you access the TYPE_STEP_COUNTER sensor, this should provide what you need.
Lastly, the Android spec allows someone to establish a "wake-up" sensor, i.e. something that turns on the application processor to signal your app and allow you to count it. In this particular case, you shouldn't do this because of the large impact on battery life.
See here from line 449 onwards, note that it allows "wake-up and non wake-up" version: 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With