Change GPS minTime when battery is low or connected to power, requestLocationUpdates

I set locationManagers as follows:

long MIN_TIME_BETWEEN_GPS_UPDATES = 0; // in min! long MAX_TIME_BETWEEN_GPS_UPDATES = 1; //in min! int DISTANCE_BETWEEN_UPDATES = 0; mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,(MAX_TIME_BETWEEN_GPS_UPDATES * 60 * 1000), DISTANCE_BETWEEN_UPDATES, mlocListener); 

Now that the charger is connected, I would like to reduce minTime

 mlocManager.removeUpdates(mlocListener); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,(MIN_TIME_BETWEEN_GPS_UPDATES * 60 * 1000), DISTANCE_BETWEEN_UPDATES, mlocListener); 

And when I disconnect the charger, I want to increase minTime, so gps gives me an update every minute.

 mlocManager.removeUpdates(mlocListener); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,(MAX_TIME_BETWEEN_GPS_UPDATES * 60 * 1000), DISTANCE_BETWEEN_UPDATES, mlocListener); 

So every time I want to change minTime, I call the .removeUpdate function and then .requestLocationUpdates is used again to change the setting.

However, this does not work for me. If I want to change the setting a second time, I need to turn on gps and turn it back on.

Anyone having trouble changing the (minTime) locationManager to change the interval between location updates?

+4
source share

Source: https://habr.com/ru/post/1439684/


All Articles