Android:GPS/传感器记录服务
我正在寻找实现定期(每 10-60 秒)记录 GPS 或其他传感器值的服务的最佳实践。当手机进入睡眠状态时,该服务应该处理待机模式。
非常感谢任何帮助,即使是伪代码!
I m looking for the best practice to implement a service for logging gps- or other sensor-values periodically (every 10-60 sec). The service should deal with the standby mode, when the phone goes asleep.
Any help, even pseudo-code, is very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来即使设备可能进入睡眠状态,也不可能让方向传感器持续工作几个小时(请参阅http://code.google.com/p/android/issues/detail?id=3708#makechanges
一旦显示屏关闭,传感器也会执行类似操作... :(
我现在实现了一个唤醒锁(需要许可)
以及一个计时器和一个广播接收器,它将再次打开显示器。这对于电池寿命来说当然是疯狂的,但到目前为止我没有找到其他方法。
这是我在服务中的 onCreate 方法:
这是服务的 onStart 方法:
这是 BroadcastReceiver 类:
适用于通过 USB 从调试器中拔出的设备(我首先遇到了这个问题)。
如果您有更好的解决方案,或者 2.3 中是否有修复,请告诉我。谢谢!
It looks like it is impossible to let the orientation sensors work constantly for hours even though the device may fall asleep (refer to http://code.google.com/p/android/issues/detail?id=3708#makechanges
As soon as the display goes off, the sensors will do alike... :(
I now implemented a wakelock (needs permission)
in conjunction with a timer and a broadcastreciever that will turn the display back on again. This is of course crazy for battery life but I found no other way so far.
This is my onCreate method in the service:
this the onStart method of the service:
and this is the BroadcastReceiver class:
This workaround will also do with a device UN-plugged from the debugger via USB (I first had an issue with this).
Please let me know if you have a better solution, or if there is fix in 2.3. Thanx!