LocationServices.SettingsApi 重置 SETTINGS_CHANGE_UNAVAILABLE 标志
LocationServices.SettingsApi Reset SETTINGS_CHANGE_UNAVAILABLE flag
更新到 Google Play Services v7.0+,并基于 this sample 中的 LocationUpdates Android,我有以下代码连接到 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
是交易:如果用户select "NEVER"执行步骤RESOLUTION_REQUIRED
时,结果将始终带有此状态。
当用户 select "NEVER" 选项时,Google Play 服务是否有一个选项可以以编程方式 重置标志?
我知道"NEVER"好像是“真的,不要再问我!!!”,但我想创建一个选项,以防用户改变主意,当然,如果可能的话。
在这种情况下,我将能够再次收到状态 RESOLUTION_REQUIRED
并要求用户在下次执行应用程序时接受 LocationUpdates。
LocationSettingsRequest.Builder has a method 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);
您将只有 Yes 和 No,因此用户不会选择 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);
更新到 Google Play Services v7.0+,并基于 this sample 中的 LocationUpdates Android,我有以下代码连接到 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
是交易:如果用户select "NEVER"执行步骤RESOLUTION_REQUIRED
时,结果将始终带有此状态。
当用户 select "NEVER" 选项时,Google Play 服务是否有一个选项可以以编程方式 重置标志?
我知道"NEVER"好像是“真的,不要再问我!!!”,但我想创建一个选项,以防用户改变主意,当然,如果可能的话。
在这种情况下,我将能够再次收到状态 RESOLUTION_REQUIRED
并要求用户在下次执行应用程序时接受 LocationUpdates。
LocationSettingsRequest.Builder has a method 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);
您将只有 Yes 和 No,因此用户不会选择 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);