gpt4 book ai didi

android - LocationServices.SettingsApi 已弃用

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:29 27 4
gpt4 key购买 nike

我的代码是:

if (mGoogleApiClient == null && checkGooglePlayService()) {
Log.d(Utils.TAG_DEV + TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
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 已被弃用。如何用新代码替换已弃用的代码?

我在阅读文档中发现可以使用 SettingsClient 解决方案,但不知道该怎么做。

知道如何更新我的代码吗?

最佳答案

LocationServices.SettingsApi deprecated

是的,LocationServices.SettingsApi已弃用

How can I replace deprecated code with the new one?

您需要使用 GoogleApi-based API SettingsClient

来自文档

SettingsClient

public class SettingsClient extends GoogleApi<Api.ApiOptions.NoOptions>

与位置设置启用程序 API 交互的主要入口点。

此 API 可让应用轻松确保设备的系统设置已根据应用的位置需求进行正确配置。

当向位置服务发出请求时,设备的系统设置可能处于阻止应用程序获取所需位置数据的状态。例如,可能会关闭 GPS 或 Wi-Fi 扫描。这个 Intent 使它很容易:

  • 确定设备上是否启用了相关系统设置以执行所需的位置请求。

  • 可选地,调用允许用户通过单击启用必要位置设置的对话框。

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

按照这个步骤

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<LocationSettingsResponse> result =
LocationServices.getSettingsClient(this).checkLocationSettings(builder.build());

关于android - LocationServices.SettingsApi 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49648054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com