当应用程序在后台运行时,Android传感器会监听 [英] Android sensor listening when app in background
问题描述
即使应用程序不在前台,是否可以连续跟踪Android上的运动传感器事件?
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.
推荐答案
首先,您可以肯定地在后台监视传感器.您需要为该类型的应用程序使用服务.这是某人创建晴雨表的示例数据记录器.您没有理由不使用其他传感器.
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.
据我所知,第二,像这样连续运行传感器会很快耗尽电池电量.本演示文稿建议,根据您的采样速度,您可能会花掉大约每小时可使用4%的电池电量.
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.
这篇关于当应用程序在后台运行时,Android传感器会监听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!