Change minTime for GPS LocationListener dynamically

自作多情 提交于 2019-12-04 06:29:06

问题


The app that I'm writing uses the GPS location manager service requestLocationUpdates() but I would like to be able to change the min Time and min Distance parameters throughout the program. I initialize the location listener on creation but I can't figure out how to change these parameters or even find out if it's possible to do that. The main purpose for this would be to conserve battery life when the program doesn't need regular position updates. Thanks so much for your help! -Dom


回答1:


I'm not sure if this is correct, but faced with the same problem, I occasionally remove the LocationListener and then later add it back with a different refresh interval:

if (locationManager != null && locationListener != null) {
    locationManager.removeUpdates(locationListener);
}

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, refreshInterval, 50, locationListener);



回答2:


Unfortunately the requestLocationUpdates() method keeps the gps on until removeUpdates() is called. In the end I used a timer to request a location and immediately removeUpdates() every minute (to conserve battery).



来源:https://stackoverflow.com/questions/5385094/change-mintime-for-gps-locationlistener-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!