12

i have added a feature in my app that uses the proximity and accelerometer sensors (the second is to detect shakes). This is implemented in an always running service (if the user selects it of course). But I fear for the battery usage that my ap will have. I have NOT used any wake locks but i still get readings even when screen is off as i can see in my logs. The question is: what of the following is true?

  1. The two mentioned sensors are activated anyway by android system the whole time (in which case me collecting the readings as well does not affect battery life...i guess).
  2. Android system turns these sensors off most of the time (in which case me keeping them always on through my service affects battery life)

If (2) is true: Is it possible to implement my own sleep cycle for the sensors or will the whole toggle process make things worse?

Anonymous
  • 4,470
  • 3
  • 36
  • 67

2 Answers2

4

Amount of power taken by the sensor varies from sensor to sensor, and device to device.

On average, your most power hungry sensors are the GPS, accelerometer and gyroscope. Leaving them ON all the time will reduce the battery faster. So you should pause the sensor when the device is where-ever not necessary.

After that, the light sensor and compass are much less battery intensive, but if you use them for long time enough even they'll affect battery life.

Besides, you can test your app for sometime how much it takes, or you can use getPower() to return the power in mA used by this sensor while in use.

There is no exact method for this actually. If your app have to use the sensor, then use it when necessary.

thanks

PrzemekTom
  • 1,328
  • 1
  • 13
  • 34
unitedartinc
  • 738
  • 1
  • 6
  • 25
  • 1
    Isn't accelerometer always on all the time anyway? At least when the screen is on...Otherwise the screen wouldn't rotate when the device rotates..In that case will my accelerometer readings affect battery life? If so i could just unregister the accelerometer when phone is locked and i would have no effect on battery whatsoever – Anonymous Jan 26 '14 at 12:21
  • 3
    accelerometer can me paused when the device is locked or gone to menu or when our app is in background.and it can be restarted when our app is back on screen.I dont know what kindoff app you made, But i used the same in my Live wallpaper app and think off how i have to use, its almost run whole time on background to give a parallax effect and i didn't got any report even with 50000 users that its draining battery, So i hope people know it will take little and they still love to use accelerometer.Btw u can view it at play store under name woody land and test it urself. thanks – unitedartinc Jan 26 '14 at 12:36
  • 1
    Accelerometers have a low-power interrupt mode specifically for cell-phones. When the accelerometer detects an orientation change, it sends an interrupt signal. The phone isn't constantly polling for sensor data. – Hans May 18 '16 at 04:59
0

u can reduce the power consumption by reading the sensor's value at some competitively larger time like 50ms, i.e. any android cell read the data at 5ms or 10ms depend on brand of cell phone and we can manually reduce that time to 50ms to 70ms. it would increase the battery life and won't affect on process as well. thank you

  • 1
    Android API only provides fixed frequency values for Sensor collection. The rate at which sensor data is collected cannot be changed apart from the provided values. https://developer.android.com/reference/android/hardware/SensorManager.html#SENSOR_DELAY_FASTEST – sparkonhdfs Jun 27 '16 at 20:23
  • 3
    @iamseiko this isn't true since `Android API 9` (Gingerbread; late 2010). You can set the sensor's sampling rate (in microseconds) using the same `registerListener(SensorEventListener, Sensor, int)` method. https://developer.android.com/reference/android/hardware/SensorManager.html – Cramps Nov 16 '16 at 07:23