问题描述
我必须在大约一天的时间建立了GPS跟踪器正在运行的应用程序。我知道在这样类似的问题,但我还没有找到任何答案,有些问题我有。
I must build an application with a GPS tracker running during about a day. I'm aware of similar questions in SO but I haven't found any answers to some questions I have.
- 我需要一个GPS定位每隔10分钟,所以我认为这样做是启动定位服务,得到了修复(或超时)的最佳方式和停止服务(与 removeUpdates( )
)。我怎样才能有一个应用程序(或服务或其他)运行这个周期每隔10min,并确保它会继续下去,只要有一定的电池留(即使设备进入睡眠状态,它应该唤醒它每10分钟得到修复)?使用AlarmManager一个好主意?
-I need a GPS fix every 10 min, so I think the best way to do it is to start the location service, get a fix (or timeout) and stop the service (with removeUpdates()
). How can I have an application (or service or whatever) running this cycle every 10min and be sure it will continue as long as there is some battery left (even if device goes to sleep, it should wake it up every 10min to get a fix)? Is using AlarmManager a good idea?
- 可我期望电池能持续1每天用这种方法?
-Can I expect the battery to last one day with this method?
我检查 mytracks 但GPS听者似乎总是在和电池预计将持续不超过5小时以上。
I've checked mytracks but the gps listener seems always on and the battery is expected to last no more than 5h.
我还检查 CWAC位置轮询但它仅 removeUpdates()
上超时,并立即重新启动监听器。它还采用了wakelock,而在我的情况,我认为一个AlarmManager可能是一个更好的主意。
I've also checked CWAC Location Poller but it does only removeUpdates()
on timeout and restart the listener immediately. It also uses a wakelock while in my case I think an AlarmManager could be a better idea.
任何帮助/建议,欢迎
推荐答案
您与报警经理当场就我用
You are spot on with alarm manager I use
Intent serviceIntent = new Intent(this, TrackerService.class);
mPendingIntent = PendingIntent.getService(this, 0, serviceIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(mPendingIntent);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), interval, mPendingIntent);
在获取网络位置的类似的应用程序
in a similar app for getting network location
间隔是启动服务之间的毫秒
interval is ms between starting the service
该服务启动时,得到的位置和关闭
the service starts up, gets the location and closes
这是更有效的电池与积极的服务恭候报告游逛
this was MUCH more battery efficient that hanging around with an active service waiting for reports
这codeI公布第一取消previous报警,这样你就不会得到超过1:)
that code i posted cancels the previous alarms first so you don't get more than 1 :)
这篇关于保持一个GPS服务活着,并优化电池寿命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!