android - How to check if location is on and in high priority on API 18 and below -
tried this:
string locationproviders = settings.secure.getstring(getactivity().getcontentresolver(), settings.secure.location_providers_allowed); log.d(tag_map, locationproviders);
output is: gps,network
are phones api 18 , below dont' have high_accuracy priority?
i assume you're wondering how using settings.secure.location_providers_allowed
, depricated in api level 19, different using settings.secure.location_mode
, introduced in api level 19.
with settings.secure.location_mode
, have these values (you know this):
location_mode_high_accuracy, location_mode_sensors_only, location_mode_battery_saving, or location_mode_off
you can map these values settings.secure.location_providers_allowed
in way:
location_mode_high_accuracy : "gps,network"
location_mode_sensors_only : "gps"
location_mode_battery_saving : "network"
location_mode_off : ""
note in code, it's best reference constants locationmanager.gps_provider
, locationmanager.network_provider
instead of "gps" , "network".
using this answer reference, this:
public static int getlocationmode(context context) { int locationmode = 0; string locationproviders; if (build.version.sdk_int >= build.version_codes.kitkat) { try { locationmode = settings.secure.getint(context.getcontentresolver(), settings.secure.location_mode); } catch (settingnotfoundexception e) { e.printstacktrace(); } } else { locationproviders = settings.secure.getstring(context.getcontentresolver(), settings.secure.location_providers_allowed); if (textutils.isempty(locationproviders)) { locationmode = settings.secure.location_mode_off; } else if (locationproviders.contains(locationmanager.gps_provider) && locationproviders.contains(locationmanager.network_provider)) { locationmode = settings.secure.location_mode_high_accuracy; } else if (locationproviders.contains(locationmanager.gps_provider)) { locationmode = settings.secure.location_mode_sensors_only; } else if (locationproviders.contains(locationmanager.network_provider)) { locationmode = settings.secure.location_mode_battery_saving; } } return locationmode; }