Better provider location management.
This commit is contained in:
parent
4e17bc3800
commit
8855235fd8
|
|
@ -3,6 +3,7 @@ package fr.chteufleur.mytrackingdog.services;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.location.LocationProvider;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -68,7 +69,12 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
try {
|
try {
|
||||||
this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
|
// if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||||
|
this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
|
||||||
|
Log.i(TAG, "Start location");
|
||||||
|
// } else {
|
||||||
|
// Log.i(TAG, "Start location failed (provider not enabled)");
|
||||||
|
// }
|
||||||
} catch (SecurityException ex) {
|
} catch (SecurityException ex) {
|
||||||
Log.e(TAG, "Location permission is not activated.", ex);
|
Log.e(TAG, "Location permission is not activated.", ex);
|
||||||
}
|
}
|
||||||
|
|
@ -77,11 +83,13 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
this.locationManager.removeUpdates(this);
|
this.locationManager.removeUpdates(this);
|
||||||
|
Log.i(TAG, "Stop location");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
|
Log.i(TAG, "onLocationChanged");
|
||||||
currentLocation = new MyLocation(location);
|
currentLocation = new MyLocation(location);
|
||||||
traces.addCurrentPoint(currentLocation);
|
traces.addCurrentPoint(currentLocation);
|
||||||
setChanged();
|
setChanged();
|
||||||
|
|
@ -90,17 +98,31 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String s, int i, Bundle bundle) {
|
public void onStatusChanged(String s, int i, Bundle bundle) {
|
||||||
stop();
|
Log.i(TAG, "onStatusChanged("+s+", "+i+", null)");
|
||||||
|
if (s != null && s.equals(LocationManager.GPS_PROVIDER)) {
|
||||||
|
if (i == LocationProvider.AVAILABLE) {
|
||||||
|
start();
|
||||||
|
} else if (i == LocationProvider.TEMPORARILY_UNAVAILABLE) {
|
||||||
|
} else if (i == LocationProvider.OUT_OF_SERVICE) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String s) {
|
public void onProviderEnabled(String s) {
|
||||||
start();
|
Log.i(TAG, "onProviderEnabled("+s+")");
|
||||||
|
if (s != null && s.equals(LocationManager.GPS_PROVIDER)) {
|
||||||
|
start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String s) {
|
public void onProviderDisabled(String s) {
|
||||||
stop();
|
Log.i(TAG, "onProviderDisabled("+s+")");
|
||||||
|
if (s != null && s.equals(LocationManager.GPS_PROVIDER)) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleTraceurActivation() {
|
public void toggleTraceurActivation() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue