king_nak
king_nak

Reputation: 11513

Android Location API: Get Provider Status

What is the best way in Android to get a location provider's status? When registering a LocationListener for location updates, the onStatusChanged(String provider, int status, Bundle extras) callback will be called whenever the status is changed. However, I didn't find a way for getting the current status (AVAILABLE, OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE) without registering to location updates. The isProviderEnabled method just indicates if the provider is generally turned on or not (in the device's settings), so might return true although the provider is out of service... Is there another way for doing this?

Another question: is it possible to listen for status updates without registering for location updates? I want to listen on a specific provider for locations, but at the same time check if others get available. My current workaround is to set the minimum time and distance to a very high value, but I wonder if there's a better solution...

Thank you for any hints!

Btw: if possible, the solutions should work with Android 1.1

Upvotes: 5

Views: 2778

Answers (1)

Stefan
Stefan

Reputation: 4705

Why do you want the GPS status, if you are not interested in the location?

However, you can get at least some aspects of the GPS status like this:

final GpsStatus gs = this.locationManager.getGpsStatus(null);
int i = 0;
final Iterator<GpsSatellite> it = gs.getSatellites().iterator();
while( it.hasNext() ) {
    it.next();
    i += 1;
}
this.gpsSatsAvailable = i;

See http://developer.android.com/reference/android/location/GpsStatus.html You will need at least 4 satellites for an accurate 2D fix, and 5 for a 3D fix (incl. altitude). According to the documentation you should access the status from onStatusChanged() to get consistent information. It works also from outside this method. The linked document explains what problems may occur. Of course, you still need to listen for location updates, because the GPS status is not updated otherwise.

Upvotes: 2

Related Questions