gpt4 book ai didi

android - LocationServices.SettingsApi 重置 SETTINGS_CHANGE_UNAVAILABLE 标志

转载 作者:可可西里 更新时间:2023-11-01 18:52:48 28 4
gpt4 key购买 nike

更新到 Google Play 服务 v7.0+,并基于 this sample对于 Android 中的 LocationUpdates,我使用以下代码连接到 LocationServices.SettingsApi 并检查用户是否一切正常,以便应用程序接收位置更新。

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

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

this 是以下回调:

    @Override
public void onResult(LocationSettingsResult locationSettingsResult) {

final Status status = locationSettingsResult.getStatus();
Intent resolutionIntent;
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// Everything is OK, starting request location updates
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Seems the user need to change setting to enable locations updates, call startResolutionForResult(Activity, REQUEST_CODE)
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Error, cannot retrieve location updates.
break;
}
}

SUCCESS 可以重现,只要保持 GPS 启用即可。

RESOLUTION_REQUIRED 也可以重现,只是禁用 GPS。

SETTINGS_CHANGE_UNAVAILABLE 是交易:如果用户在执行步骤 RESOLUTION_REQUIRED 时选择“NEVER”,结果将始终带有此状态。

当用户选择“从不”选项时,Google Play 服务是否有一个选项可以以编程方式重置标志?

我知道“从不”似乎是“真的,不要再问我!!!”,但我想创建一个选项以防万一如果可能的话,用户当然会改变主意。

在这种情况下,我将能够再次收到状态 RESOLUTION_REQUIRED 并要求用户在下次执行应用程序时接受 LocationUpdates。

最佳答案

LocationSettingsRequest.Builder有一个方法 setAlwaysShow改变对话框的按钮:

Always show the dialog, without the "Never" option to suppress future dialogs from this app. When this flag is set to true, the dialog will show up if the location settings do not satisfy the request, even if a user has previously chosen "Never". NOTE: Only use this method if your dialog is the result of an explicit user-initiated action that requires location to proceed. Canceling this dialog should also cancel the initiated action.

如果您调用 setAlwaysShow(true);,则使用默认的YesNot nowNever 按钮代替将只有 YesNo,因此用户不会选择 Never,您将永远不会收到 SETTINGS_CHANGE_UNAVAILABLE

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
mLocationSettingsRequest = builder.build();

PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);

result.setResultCallback(this);

关于android - LocationServices.SettingsApi 重置 SETTINGS_CHANGE_UNAVAILABLE 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861580/

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