2

Until last update I used next code:

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
        builder.addLocationRequest(mLocationRequest);
        builder.setAlwaysShow(true);
        mLocationSettingsRequest = builder.build();

        PendingResult<LocationSettingsResult> result =
                LocationServices.SettingsApi.checkLocationSettings(
                        mGoogleApiClient,
                        mLocationSettingsRequest
                );
        result.setResultCallback(this);

Unfortunately after update a warning message pup-up that LocationServices.SettingsApi is deprecated. How to change my code to fit to new updates?

MMG
  • 3,226
  • 5
  • 16
  • 43
gogoloi
  • 627
  • 3
  • 8
  • 19

1 Answers1

9

SettingsApi interface is Deprecated. You should use GoogleApi-based API SettingsClient instead.

public class SettingsClient extends GoogleApi

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.

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest); // mLocationRequest is a Object of LocationRequest
    LocationSettingsRequest locationSettingsRequest = builder.build();

    SettingsClient settingsClient = LocationServices.getSettingsClient(this);
    settingsClient.checkLocationSettings(locationSettingsRequest);
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    can't figure out how to implement this part: PendingResult result = settingsClient.checkLocationSettings( mGoogleApiClient, mLocationSettingsRequest ); result.setResultCallback(this); – gogoloi May 09 '18 at 11:28
  • sorry I am new with java. – gogoloi May 09 '18 at 11:28
  • Google just deprecated GoogleApiCLient. https://developers.google.com/android/guides/google-api-client Look at https://developer.android.com/training/location/ – Aris Bartee May 09 '18 at 15:52