Change minTime for GPS LocationListener dynamically

对着背影说爱祢 提交于 2019-12-02 12:31:34
Judah Sali

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

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

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