This question already has answers here:
LocationServices.SettingsApi deprecated
(3个答案)
去年关闭。
在上次更新之前,我使用了下一个代码:
不幸的是,在更新警告消息后,LocationServices.SettingsApi已被弃用。如何更改我的代码以适合新的用户?
(3个答案)
去年关闭。
在上次更新之前,我使用了下一个代码:
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);
不幸的是,在更新警告消息后,LocationServices.SettingsApi已被弃用。如何更改我的代码以适合新的用户?
最佳答案
SettingsApi
接口已弃用。您应该改用基于GoogleApi的API SettingsClient
。
公共类SettingsClient扩展
GoogleApi
通过此API,应用程序可以轻松确保正确配置设备的系统设置以满足应用程序的位置需求。
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);
Get current location settings.
Working with the user's location settings.
09-25 16:18