Android LocationManger 进入睡眠状态?
我正在开发一个位置记录应用程序,每秒保存一个手机位置。
我已经实现了一个订阅 LocationManager 更新的服务:
HandlerThread thread = new HandlerThread("LocationServiceHandler");
locationManager.requestLocationUpdates(GPS_PROVIDER,
1000 /* milliseconds*/, 0 /* meters */, listener, thread.getLooper());
该服务通过绑定到应用程序上下文启动。
应用程序通常在后台运行,不需要任何用户交互。
一般来说,当我在建筑物周围走动时,它工作正常 - 该服务每秒获取一个新位置+时间戳并将其存储到位于外部存储的文件中。
但是当我到达远离城市的空旷场地时,我发现日志文件中的记录之间有 4-5 分钟的间隙。我可以肯定地说,当时手机没有在使用,而且它在开阔的天空下,没有任何可见的东西阻挡卫星。这种情况发生不规律,大约每小时一次,我无法在我的办公室重现这种行为。
有什么想法,可能是什么原因造成的?如何避免?
手机是 Nexus S,Android 2.3.4
I'm developing a location logging application that saves a phone location each second.
I've implemented a service that subscribes to LocationManager updates:
HandlerThread thread = new HandlerThread("LocationServiceHandler");
locationManager.requestLocationUpdates(GPS_PROVIDER,
1000 /* milliseconds*/, 0 /* meters */, listener, thread.getLooper());
The service started by binding to an application context.
Application usually runs in a background and doesn't requires any user interaction.
Generally it works OK when I'm walking around my building - the service gets a new location+timestamp each second and stores it to a file located at external storage.
But when I'm getting to an open field away from a city, I found a 4-5 minutes gaps between records in a log file. I can say for sure that the phone wasn't in use at that moment and it was under the open sky, nothing visible was blocking a satellites. It happens irregularly, aprox once a hour and I can't reproduce this behavior at my office.
Any ideas, what might cause that? How can it be avoided?
The phone is Nexus S, Android 2.3.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用唤醒锁吗?手机可能会进入睡眠状态,因此您会错过位置。否则,可能只是位置管理器不为您提供位置,因为 1000 毫秒是最好的情况。请参阅每 5 秒更新一次 GPS 侦听器答案。
Are you using a wakelock? The phone might go to sleep and you therefore misses locations. Otherwise it might just be the locationmanager that just don't give you the location since the 1000 ms is a best case scenario. Please see Update GPS Listener every 5 seconds answers.