Android 传感器在后台应用程序时侦听 [英] Android sensor listening when app in background

查看:27
本文介绍了Android 传感器在后台应用程序时侦听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 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.

推荐答案

首先,你绝对可以在后台监控传感器.您需要为该类型的应用程序使用服务.这是某人创建晴雨表的示例 data记录器.没有任何理由不能使用不同的传感器.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆