【发布时间】:2017-12-19 04:28:36
【问题描述】:
当我调用以使用 GoogleApiClient 以编程方式启用 gps 进入片段时出现问题... 我的代码是..
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;
}
但是我的 onAccticvityResult() 没有在片段中执行。 问题出在哪里??? 帮助我.....提前谢谢。
【问题讨论】:
-
在该片段的 Activity 类中创建一个 onActivityResult 并在其中放置一个调试器进行检查
-
如果您以 getActivity().startActivityForResult(...) 的形式开始您的活动,请将其替换为 startActivityForResult(...);。
-
onActivityResult 执行的 Activity 但是当我从 Activity 调用片段的任何函数时,上下文总是为空
-
@SubhechhuKhanal 我不是在调用 startActivityForResult,而是在调用 startResolutionForResult。
-
如果你的活动 onActivityResult() 被调用,你不能从活动的 onActivityResult() 调用片段的 onActivityResult() 吗? fragment.onActivityResult(requestCode, resultCode, data)
标签: android gps location onactivityresult