问题
I have an application which uses Network provider for it's location. Everytime the apps starts it checks to see whether Network provider is enabled using isProviderEnabled() method in LocationManager. If it returns false I present an alert to the user to enable Network Provider and then use the application. This logic had been working really well, with a few exceptions with non-Google certified devices(not a concern since, they usually do not have Maps API either). Lately, with some devices on ICS and now on JellyBean emulator I get a consistent "false" for isProviderEnabled() even though it is enabled.
I have since moved to using the string returned from Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED)) to see whether it contains "network". It is a hack but it is working for now. I would love to be able to use isProviderEnabled() method.
Has anyone see this issue before?
回答1:
From the API doc for : LocationManager.GPS_PROVIDER
This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission ACCESS_FINE_LOCATION.
So if you're not requiring ACCESS_FINE_LOCATION it will return false.
回答2:
@naqi @gkris
I also noticed this issue where isProviderEnabled(LocationManager.GPS_PROVIDER)
was returning false
.
Solution to this is to also ask user to set the Location Method
to High Accuracy
instead of Battery Saving
or Device Only
This setting is available under location settings and has different name on different devices. On some devices that I have tested on, this setting is with name Mode
, Location Mode
, Location Method
etc Also the value can be High Accuracy
or GPS
or GPS, Wifi and Mobile Networks
Developers will have to train users on this.
来源:https://stackoverflow.com/questions/11437327/android-locationmanager-isproviderenabled-always-returns-false