A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient below:

SettingsClient | Google Play services

SettingsClient

Stay organized with collections Save and categorize content based on your preferences.

The main entry point for interacting with the location settings-enabler APIs.

This API makes it easy for an app to ensure that the device's system settings are properly configured for the app's location needs.

When making a request to location services, the device's system settings may be in a state that prevents an app from obtaining the location data that it needs. For example, GPS or Wi-Fi scanning may be switched off. This intent makes it easy to:

To use this API, first create a LocationSettingsRequest.Builder and add all of the LocationRequests that the app will be using:

 LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
     .addLocationRequest(mLocationRequestHighAccuracy)
     .addLocationRequest(mLocationRequestBalancedPowerAccuracy);

If the client is using BLE scans to derive location, it can request that BLE be enabled by calling LocationSettingsRequest.Builder.setNeedBle(boolean):

 builder.setNeedBle(true);

Then check whether current location settings are satisfied:

 Task<LocationSettingsResponse> result =
         LocationServices.getSettingsClient(this).checkLocationSettings(builder.build());

When the Task completes, the client can check the location settings by looking at the status code from the LocationSettingsResponse object. The client can also retrieve the current state of the relevant location settings by calling LocationSettingsResponse.getLocationSettingsStates():

 task.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
     @Override
     public void onComplete(Task<LocationSettingsResponse> task) {
         try {
             LocationSettingsResponse response = task.getResult(ApiException.class);
             // All location settings are satisfied. The client can initialize location
             // requests here.
             ...
         } catch (ApiException exception) {
             switch (exception.getStatusCode()) {
                 case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                     // Location settings are not satisfied. But could be fixed by showing the
                     // user a dialog.
                     try {
                         // Cast to a resolvable exception.
                         ResolvableApiException resolvable = (ResolvableApiException) exception;
                         // Show the dialog by calling startResolutionForResult(),
                         // and check the result in onActivityResult().
                         resolvable.startResolutionForResult(
                             OuterClass.this,
                             REQUEST_CHECK_SETTINGS);
                     } catch (SendIntentException e) {
                         // Ignore the error.
                     } catch (ClassCastException e) {
                         // Ignore, should be an impossible error.
                     }
                     break;
                 case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                     // Location settings are not satisfied. However, we have no way to fix the
                     // settings so we won't show the dialog.
                     ...
                     break;
              }
         }
     }
 });

If the status code is CommonStatusCodes.RESOLUTION_REQUIRED, the client can call ResolvableApiException.startResolutionForResult(Activity, int) to bring up a dialog, asking for the user's permission to modify the location settings to satisfy those requests. The result of the dialog will be returned via Activity.onActivityResult(int, int, Intent). If the client is interested in which location providers are available, it can retrieve a LocationSettingsStates from the Intent by calling LocationSettingsStates.fromIntent(Intent):

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     final LocationSettingsStates states = LocationSettingsStates.fromIntent(intent);
     switch (requestCode) {
         case REQUEST_CHECK_SETTINGS:
             switch (resultCode) {
                 case Activity.RESULT_OK:
                     // All required changes were successfully made
                     ...
                     break;
                 case Activity.RESULT_CANCELED:
                     // The user was asked to change settings, but chose not to
                     ...
                     break;
                 default:
                     break;
             }
             break;
     }
 }
Public Methods public abstract Task<LocationSettingsResponse> checkLocationSettings (LocationSettingsRequest locationSettingsRequest)

Checks if the relevant system settings are enabled on the device to carry out the desired location requests.

Parameters locationSettingsRequest an object that contains all the location requirements that the client is interested in. public abstract Task<Boolean> isGoogleLocationAccuracyEnabled ()

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-10-31 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["The `SettingsClient` helps ensure device settings are properly configured for an app's location needs, such as enabling GPS or Wi-Fi scanning."],["Developers can use it to check if location settings are satisfied and optionally prompt the user to enable necessary settings via a dialog."],["If location settings are not satisfied, but can be fixed by user intervention, a resolvable exception is provided to show a settings dialog."],["The `SettingsClient` also provides a method to determine if Google Location Accuracy is enabled, which is necessary for network-based locations."],["Upon the user responding to the settings dialog, developers can handle the outcome in the `onActivityResult` method of their Activity."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4