Android sensor listening when app in background

左心房为你撑大大i 提交于 2019-11-29 12:24:41

问题


Is it possible to track motion sensor events on Android continuously, even if the app is not in foreground?

If yes - what's the drain on battery?

A client asked if it would be possible to write an app that would initiate an action if the person "falls" - which basically means continuously listening to the motion sensor for rapid movement.


回答1:


First, you can definitely monitor the sensors in the background. You need to use a service for that type of application. Here is an example of someone creating a barometer data logger. There's not really any reason you couldn't use different sensors.

Second, as far as I'm aware, running the sensors continuously like that would drain the battery quickly. This presentation suggests that depending on your sampling speed, you could burn through about 4% of the battery per hour on the sensor use.

Lastly, you can definitely wake the phone and take action upon an event received by that service. See this question.



来源:https://stackoverflow.com/questions/22093572/android-sensor-listening-when-app-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!