gpt4 book ai didi

java - LocationSettingsStates 类在接收位置请求时会做什么?

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:50 25 4
gpt4 key购买 nike

在文档中here我正在关注如何接收位置请求,并且我注意到这两个代码块中有两个不寻常的事情:

result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates = result.getLocationSettingsStates(); //<--This line I don't understand
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
...
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(
OuterClass.this,
REQUEST_CHECK_SETTINGS);
} catch (SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way to fix the
// settings so we won't show the dialog.
...
break;
}
}
});

在第二个 block 中:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
final LocationSettingsStates states = LocationSettingsStates.fromIntent(intent); //<--And this line
switch (requestCode) {
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
// All required changes were successfully made
...
break;
case Activity.RESULT_CANCELED:
// The user was asked to change settings, but chose not to
...
break;
default:
break;
}
break;
}
}

我添加了一些箭头指向我不理解的行。特别是这两个:

最终 LocationSettingsStates = result.getLocationSettingsStates();

final LocationSettingsStates states = LocationSettingsStates.fromIntent(intent);

第一行是我以前从未见过的。将值分配给数据类型如何有效?那么该类在该代码块的其他任何地方都不再使用,那么赋值的目的是什么?

在另一行中,现在它正在为该数据类型的名为 states 的实例分配一个值,但该实例未在 onActivityResult() 中的其他任何地方使用。

那么这是怎么回事呢?谢谢。

最佳答案

第一行肯定是一个拼写错误;它应该是这样的:

final LocationSettingsStates states = result.getLocationSettingsStates();

是的,这两个地方都没有使用它,这很奇怪,但你可以调用 things就像 isBleUsable() 一样,以确定现在到底存在和可用的内容。在后一种情况下,它是尝试解决后可用的内容。

关于java - LocationSettingsStates 类在接收位置请求时会做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37242018/

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