Reputation: 25
My app takes the users location through Wi-Fi/3G which ever is enabled, however there is an option in the phones settings to disable to not allow applications to get your location.
My question is how can i check to see if this is enabled/disabled before I try to take their location?
Currently I'm using:
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String provider = LocationCall.getBestProvider(criteria, true);
if (provider == null) {
//No internet connection available OR location services has been turned off
}
This works but I want to be able to tell the user exactly why I cant take their location.
Solution:
String provider = LocationCall.getBestProvider(criteria, true);
if ("gps".equals(provider) || provider == null) {
Toast.makeText(getApplicationContext(), "Use Wireless Networks has been disabled in location settings", Toast.LENGTH_LONG).show();
}
If provider is equal only to gps or is null then the user has disabled applications to get their location through network.
Upvotes: 0
Views: 729
Reputation: 4799
I wrote a blog post about Android location services and it contains example code on how to check which providers are enabled, alert the user and then take them to the settings screen to enable them. You can find it here: http://www.scotthelme.co.uk/blog/android-location-services/
Upvotes: 1