LocationServices.SettingsApi deprecated

后端 未结 4 1727
不知归路
不知归路 2020-12-18 20:01

My code is:

if (mGoogleApiClient == null && checkGooglePlayService()) {
        Log.d(Utils.TAG_DEV + TAG, \"Building GoogleApiClient\");
        mGo         


        
4条回答
  •  遥遥无期
    2020-12-18 20:38

    LocationServices.SettingsApi deprecated

    Yes, LocationServices.SettingsApi is deprecated

    How can I replace deprecated code with the new one?

    You need to use GoogleApi-based API SettingsClient

    FROM DOCS

    SettingsClient

    public class SettingsClient extends GoogleApi
    

    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:

    • Determine if the relevant system settings are enabled on the device to carry out the desired location request.

    • Optionally, invoke a dialog that allows the user to enable the necessary location settings with a single tap.

    I found reading docs that the solution can be to use SettingsClient but couldn't figure how to do it.

    Follow this steps

    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)
    

    Then check whether current location settings are satisfied:

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

提交回复
热议问题