gpt4 book ai didi

android - 在 fragment 中开始解析结果

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

在我的应用程序中,如果用户没有打开位置,我会通过对话框进行提示,然后尝试通过覆盖 Activity 结果来返回该结果(可能是错误的)。

这是在一个 fragment 中,所以不确定它是如何改变的:

这就是我如何将其称为带有 startResolutionForResult 的对话框:

public void checkDeviceLocationIsOn()
{
System.out.println("Test running setting request" );
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(true); //this is the key ingredient

PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied.
System.out.println("Test setting all fine starting location request" );
getLocation();
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(getActivity(), LOCATION_SETTINGS_REQUEST_CODE);
System.out.println("Test setting not met starting dialog to prompt user" );
} catch (IntentSender.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;
}
}
});
}

然后我尝试在它下面得到这样的结果(这永远不会被调用):

   @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
// Check for the integer request code originally supplied to startResolutionForResult().
case LOCATION_SETTINGS_REQUEST_CODE:
switch (resultCode) {
case Activity.RESULT_OK:
System.out.println("test user has turned the gps back on");
getLocation();
break;
case Activity.RESULT_CANCELED:

System.out.println("test user has denied the gps to be turned on");
Toast.makeText(getActivity(), "Location is required to order stations", Toast.LENGTH_SHORT).show();
break;
}
break;
}
}

预先感谢您的帮助

最佳答案

调用 fragment 方法

startIntentSenderForResult(status.getResolution().getIntentSender(), REQUEST_CODE_LOCATION_SETTING, null, 0, 0, 0, null);

代替

status.startResolutionForResult(...)

关于android - 在 fragment 中开始解析结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40110823/

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