mittelmania mittelmania - 4 years ago 142
Android Question

Android smart power management using sensor data

I'm working on an Android application that needs to scan nearby Wi-Fi access points on a regular basis. Currently the scan takes place every 2-3 minutes, which requires registering a

to capture the scan results, calling
method and processing the results (something that also requires network calls in my case). This loop consumes a lot of energy, and I want to improve my power consumption by implementing a smart power policy for the app.

Aside from scanning only on "busy hours" (for example, stopping the loop at night), I'm thinking about using the accelerometer through the
to detect whether the device is stationary (placed on a table) or in motion (in the user's pocket while walking, for example). Then, by determining if the device is moving, I can adjust the scan frequency (reduce when it is stationary, and increase when the device is in motion).

I have a few questions on the matter:

1) Will tracking accelerometer data on a regular basis be more power efficient than running the scan loop every 3-5 minutes? How much power will tracking the accelerometer really cost?

2) How can I determine if the device is stationary or in motion? I've seen many question online talking about detecting shakes and tilts, but there's not a lot of information about natural motion detection. Also, how frequently should I sample the sensor?

Answer Source

I think the best way is to use ActivityRecognitionApi class included in the google play sevices which is optimized for such goals. This class gives a method : requestActivityUpdates which is optimized to return device state with minimum consumption of power.

The activities are detected by periodically waking up the device and reading short bursts of sensor data. It only makes use of low power sensors in order to keep the power usage to a minimum.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download