From 9340e2122e5a34bddb32a83b721b797f694e590f Mon Sep 17 00:00:00 2001 From: Fred Chung Date: Mon, 16 Apr 2012 00:40:06 -0700 Subject: Updated "Making your App Location Aware" class to include information on location provider enable check. Change-Id: Ie6e966b4204eed60f518759480cebc945f87d91f --- docs/html/shareables/training/LocationAware.zip | Bin 36310 -> 261408 bytes docs/html/training/location/locationmanager.jd | 30 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'docs/html') diff --git a/docs/html/shareables/training/LocationAware.zip b/docs/html/shareables/training/LocationAware.zip index 46970cd..8ed97cb 100644 Binary files a/docs/html/shareables/training/LocationAware.zip and b/docs/html/shareables/training/LocationAware.zip differ diff --git a/docs/html/training/location/locationmanager.jd b/docs/html/training/location/locationmanager.jd index 5da1205..61abcbd 100644 --- a/docs/html/training/location/locationmanager.jd +++ b/docs/html/training/location/locationmanager.jd @@ -18,6 +18,7 @@ next.link=currentlocation.html
  • Declare Proper Permissions in Android Manifest
  • Get a Reference to LocationManager
  • Pick a Location Provider
  • +
  • Verify the Location Provider is Enabled
  • You should also read

    @@ -88,3 +89,32 @@ if (providerName != null) { ... } + +

    Verify the Location Provider is Enabled

    + +

    Some location providers such as the GPS can be disabled in Settings. It is good practice to check whether the desired location provider is currently enabled by calling the {@link android.location.LocationManager#isProviderEnabled(java.lang.String) isProviderEnabled()} method. If the location provider is disabled, you can offer the user an opportunity to enable it in Settings by firing an {@link android.content.Intent} with the {@link android.provider.Settings#ACTION_LOCATION_SOURCE_SETTINGS} action.

    + +
    +@Override
    +protected void onStart() {
    +    super.onStart();
    +
    +    // This verification should be done during onStart() because the system calls
    +    // this method when the user returns to the activity, which ensures the desired
    +    // location provider is enabled each time the activity resumes from the stopped state.
    +    LocationManager locationManager =
    +            (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    +    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    +
    +    if (!gpsEnabled) {
    +        // Build an alert dialog here that requests that the user enable
    +        // the location services, then when the user clicks the "OK" button,
    +        // call enableLocationSettings()
    +    }
    +}
    +
    +private void enableLocationSettings() {
    +    Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    +    startActivity(settingsIntent);
    +}
    +
    -- cgit v1.1