Android: How to check if a LocationProvider is available?

In Android the LocationProvider for example for GPS might not be available.

You can find out if a LocationManager is enabled via the isProviderEnabled() method. If its not enabled you can send the user to the settings via an Intent with the Settings.ACTION_LOCATION_SOURCE_SETTINGS action for the android.provider.Settings class.

This is demonstrated via the following code snippets:

LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service

// Check if enabled and if not send user to the GSP settings
// Better solution would be to display a dialog and suggesting to
// go to the settings
if (!enabled) {
  Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

You find more info about the LocationManager in Location API and Google Maps in Android – Tutorial

Written by admin in: sample code |

No Comments

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

AndGPS | Connect Android Phone To GPS Solutions