gpt4 book ai didi

android - 当我调用 startResolutionForResult 时,onActivityResult() 没有在 fragment 中执行

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:48:22 26 4
gpt4 key购买 nike

当我调用以编程方式使用 GoogleApiClient 将 gps 启用到 fragment 中时出现问题...我的代码是..

 final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode())
{
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
getCurrentLocation();
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(), REQUEST_ID_GPS_PERMISSIONS);
} 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;
}

我的 onActivityResult 是

 final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode())
{
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
getCurrentLocation();
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(), REQUEST_ID_GPS_PERMISSIONS);
} 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;
}

但是我的 onActicvityResult() 没有在 fragment 中执行。问题出在哪里???帮助我.....提前致谢。

最佳答案

将此行用于 Fragment 以在 onActivityResult 中获取结果

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

代替

 status.startResolutionForResult(getActivity(), REQUEST_ID_GPS_PERMISSIONS);

关于android - 当我调用 startResolutionForResult 时,onActivityResult() 没有在 fragment 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45096727/

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