Change minTime for GPS LocationListener dynamicall

2019-03-03 18:40发布

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

2条回答
女痞
2楼-- · 2019-03-03 19:11

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);
查看更多
干净又极端
3楼-- · 2019-03-03 19:17

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).

查看更多
登录 后发表回答