1

Recently I tried to make an app which gives user step count. And came across step count and detector which was introduced in Android 4.4. but I can't find a way to do step counting hourly basis. I am new to this any guidance will be highly appreciated

I found on this https://developer.android.com/reference/android/hardware/SensorManager.html#registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int)

That editing the third parameter I can specify delay while doing following    boolean registerListener (SensorEventListener listener,                Sensor sensor,                int samplingPeriodUs)

But it accepts value in milliseconds and convert one hour into milliseconds gives a very large int value. Can anyone guide on how to deal with it

GPW
  • 305
  • 1
  • 2
  • 15

1 Answers1

1

What are you are looking for is Sensor Batching.

That allows you to get continuous sensor data even without keeping the device awake. It basically stores the sensor events in a hw based queue right in the chip itself and only sends them to your app (service,..) at predefined intervals in batches. This allows you to do a 24/7 monitoring without draining the battery significantly. Please note that only supported chipsets can do that (you can find details in Android docs), in case of older phones you need to fallback to the hideous wakelock keeping method in order to get your data. Source

Also there is example how to use BatchStepSensor

Community
  • 1
  • 1
Jozef Dochan
  • 920
  • 9
  • 25