tags:

views:

25

answers:

0

I've carefully read this thread: http://stackoverflow.com/questions/2021176/android-gps-status but it still didn't illuminated me.

I want to achieve a very simple thing: I have 3 satellite icons: one red, one orange and one green. When the user is in the activity that uses the gps I have the satellite icon on a corner and I simply want to change its color depending on current state:

  • if disabled - red
  • if enabled and looking for a fix - orange
  • if locked on the satellites - green.

Here is what I did until now:

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,

0, 0, mlocListener);

public class MyLocationListener implements LocationListener
{
       public void onLocationChanged(Location location)
       {
         if (location != null) {...}
        }
}
void onStatusChanged(final String provider, final int status,
        final Bundle extras) {
    switch (status) {
    case LocationProvider.OUT_OF_SERVICE:
        if (location == null || location.getProvider().equals(provider)) {
            //set the image to red icon
            location = null;
        }
        break;
    case LocationProvider.AVAILABLE:
        //set the icon green
        break;
    }
}

How can I achieve this GPS icon status in code ? The onStatusChange doesn't seem to fire in Eclair and Froyo.