Fixed issue 307 to work also on android 1.5 and above without
problems.
This commit is contained in:
parent
6524326989
commit
18c04e398b
1 changed files with 22 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.activities;
|
package net.osmand.activities;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
@ -81,9 +82,7 @@ public class DayNightHelper implements SensorEventListener {
|
||||||
if (currentTime - lastAutoCall > 5000) {
|
if (currentTime - lastAutoCall > 5000) {
|
||||||
lastAutoCall = System.currentTimeMillis();
|
lastAutoCall = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
LocationManager locationProvider = (LocationManager) osmandApplication.getSystemService(Context.LOCATION_SERVICE);
|
Location lastKnownLocation = getLocation();
|
||||||
// Or use LocationManager.GPS_PROVIDER
|
|
||||||
Location lastKnownLocation = locationProvider.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
|
||||||
if(lastKnownLocation == null){
|
if(lastKnownLocation == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -111,6 +110,26 @@ public class DayNightHelper implements SensorEventListener {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Location getLocation() {
|
||||||
|
Location lastKnownLocation = null;
|
||||||
|
LocationManager locationProvider = (LocationManager) osmandApplication.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
List<String> providers = new ArrayList<String>(locationProvider.getProviders(true));
|
||||||
|
//note, passive provider is from API_LEVEL 8 but it is a constant, we can check for it.
|
||||||
|
int passiveFirst = providers.indexOf(LocationManager.PASSIVE_PROVIDER);
|
||||||
|
//put passive provider to first place
|
||||||
|
if (passiveFirst > -1) {
|
||||||
|
providers.add(0,providers.remove(passiveFirst));
|
||||||
|
}
|
||||||
|
//find location
|
||||||
|
for (String provider : providers) {
|
||||||
|
lastKnownLocation = locationProvider.getLastKnownLocation(provider);
|
||||||
|
if (lastKnownLocation == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastKnownLocation;
|
||||||
|
}
|
||||||
|
|
||||||
public void onMapPause() {
|
public void onMapPause() {
|
||||||
unregisterServiceListener();
|
unregisterServiceListener();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue