Kasas Kasas - 5 months ago 39
Android Question

IsProviderEnabled for GPS is not working

we have implemented a geobased app for Android, so we need to ensure GPS is enabled all the time. The problem is that

manager.isProviderEnabled( LocationManager.GPS_PROVIDER )


is always returning false even if the GPS Provider is enabled, so our app is always showing the alert to change the GPS status or it is not working.

Do you know what is happening?

We are testing it with a Samsung Galaxy S and a HTC Wildfire device...
Thanks in advance.

Answer

You can get GPS status directly from system:

LocationManager myLocationManager = (LocationManager)  getSystemService(Context.LOCATION_SERVICE);

private boolean getGPSStatus()
{
   String allowedLocationProviders =
   Settings.System.getString(getContentResolver(),
   Settings.System.LOCATION_PROVIDERS_ALLOWED);

   if (allowedLocationProviders == null) {
      allowedLocationProviders = "";
   }

   return allowedLocationProviders.contains(LocationManager.GPS_PROVIDER);
}