Search code examples
androidgeolocationxamarin.androidlocationmanagerairplane-mode

Android: LocationManager when Airplane mode on


I am testing the location part of my app with various configurations. In AirPlane mode I don't get any message sent to ILocationListener, good or bad, from the following LocationManager on an Android 2.2. In this case the bestProvider is "network".

How can I determine if there simply is no way to get a location so that I can inform the user? When there is a network or GPS it all works fine.

The code I use (Mono for Android C#) is:

            var cr = new Criteria ();
            cr.Accuracy = Accuracy.Coarse;
            cr.PowerRequirement = Power.Low;
            cr.AltitudeRequired = false;
            cr.BearingRequired = false;
            cr.SpeedRequired = false;
            cr.CostAllowed = true;
            string serviceString = Context.LocationService;
            locationManager = (LocationManager)GetSystemService (serviceString);
            var bestProvider = locationManager.GetBestProvider (cr, false);
            locationManager.RequestLocationUpdates (bestProvider, 5000, 500f, this);

Solution

  • as this is your Location Listener you can see the state in onProviderEnabled (String provider), onProviderDisabled (String provider) or onStatusChanged (String provider, int status, Bundle extras). Read this API for further Information, what each state means