开发者

Android LocationManger goes to sleep?

开发者 https://www.devze.com 2023-03-29 00:45 出处:网络
I\'m developing a location logging application that saves a phone location each second. I\'ve implemented a service that subscribes to LocationManager updates:

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("LocationSer开发者_如何学编程viceHandler");
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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号