We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesLocation KitAndroidcom.huawei.hms.locationClass SummarySettingsClient

SettingsClient

Expand

Class Info

public class SettingsClient

Location setting check class. An instance of this class will be returned when the getSettingsClient(Context context) or getSettingsClient(Activity activity) method in the LocationServices class is called.

The following sample code checks the location settings:
Java
Kotlin
Collapse
Word wrap
Dark theme
Copy code
  1. SettingsClient settingsClient = LocationServices.getSettingsClient(this);
  2. LocationRequest locationRequest = new LocationRequest();
  3. LocationSettingsRequest.Builder builder =
  4. new LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
  5. .setAlwaysShow(false)
  6. .setNeedBle(false);
  7. settingsClient.checkLocationSettings(builder.build())
  8. .addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
  9. @Override
  10. public void onComplete(Task<LocationSettingsResponse> task) {
  11. if (task != null && task.isSuccessful()) {
  12. LocationSettingsResponse response = task.getResult();
  13. if (response == null) {
  14. return;
  15. }
  16. LocationSettingsStates locationSettingsStates = response.getLocationSettingsStates();
  17. // TODO: Process the result returned when the API call is successful.
  18. }
  19. }
  20. })
  21. .addOnFailureListener(new OnFailureListener() {
  22. @Override
  23. public void onFailure(Exception e) {
  24. Log.i(TAG, "checkLocationSetting onFailure:" + e.getMessage());
  25. }
  26. });
Collapse
Word wrap
Dark theme
Copy code
  1. val settingsClient = LocationServices.getSettingsClient(this)
  2. val locationRequest = LocationRequest()
  3. val builder =
  4. LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
  5. .setAlwaysShow(false)
  6. .setNeedBle(false)
  7. settingsClient.checkLocationSettings(builder.build())
  8. .addOnCompleteListener { task ->
  9. if (task != null && task.isSuccessful) {
  10. val response = task.result ?: return@addOnCompleteListener
  11. val locationSettingsStates =
  12. response!!.locationSettingsStates
  13. // TODO: Process the result returned when the API call is successful.
  14. }
  15. }
  16. .addOnFailureListener { e ->
  17. Log.i(TAG, "checkLocationSetting onFailure:" + e.message)
  18. }

Public Method Summary

Expand

Qualifier and Type

Method Name and Description

Task<LocationSettingsResponse>

checkLocationSettings(LocationSettingsRequest locationSettingsRequest)

Checks whether relevant location settings are valid.

Task<Void>

setLogConfig(LogConfig logConfig)

Sets whether to enable log recording.

Public Methods

checkLocationSettings

Expand

Method

public Task<LocationSettingsResponse> checkLocationSettings(LocationSettingsRequest locationSettingsRequest)

Checks whether relevant location settings are valid.

To use this method, you must first create a LocationSettingsRequest.Builder class and add the LocationRequest object that will be used by your app.

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);

Then, call the checkLocationSettings method.

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

Your app can call getLocationSettingsStates() to obtain the current status of relevant location settings.

Parameters

Expand

Name

Description

locationSettingsRequest

Request object related to location settings.

Returns

Expand

Type

Description

Task<LocationSettingsResponse>

Task execution result. You can add listeners using addOnSuccessListener() and addOnFailureListener() to obtain the current method execution result. If the result is failure, convert the thrown Exception object into an ApiException object, and then call the getStatusCode() method of the ApiException object to obtain the result code.

If the result code is 6, the task execution failed. (You can instruct users to modify the location settings to solve the problem.)

setLogConfig

Expand

Method

public Task<Void> setLogConfig(LogConfig logConfig)

Sets whether to enable log recording.

To use this method, create SettingsClient settingsClient = LocationServices.getSettingsClient(this), create LogConfig logConfig = new LogConfig(), set parameters for logConfig, and call the setLogConfig() method of SettingsClient to enable log recording.

Parameters

Expand

Name

Description

logConfig

Request parameters for log recording.

Returns

Expand

Type

Description

Task<Void>

Task execution result. You can add listeners using addOnFailureListener() to obtain the current method execution result. If the result is failure, call the getMessage() method of the Exception object to obtain the failure reason. If no error information is returned, log recording is enabled successfully.

Search in References
Enter a keyword.