I'm trying to set up location services on my app.
I'd like to show the user an error in a case where there is no GPS signal available(After X minutes of trying to find a signal).
How can I do that?
Here's my code so far -
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
Log.d("loca", "accuracy - " + location.getAccuracy());
Log.d("loca", "longtitude - " + location.getLongitude());
Log.d("loca", "Latitude - " + location.getLatitude());
Log.d("loca", "Provider - " + location.getProvider());
if(isBetterLocation(location,bestLoc))
{
Log.d("loca", "best loc - yes");
bestLoc = location;
}
else
Log.d("loca", "best loc - no");
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,TWO_MINUTES , 300, locationListener);
Log.d("loca", "GPS");
}
else if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,TWO_MINUTES , 300, locationListener);
Log.d("loca", "Net");
}
else
Log.d("loca", "Nothing");
How can I know how long it has been since I've started looking for a signal?
Thanks!