在我的应用程序中,我正在使用Google地图,这就是为什么我要检查权限,如下所示:
if (!Constant.checkPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {
Constant.requestPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION, 101);
} else {
if (Constant.isOnline(getActivity())) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
mGoogleApiClient.connect();
locationUpdate();
} else {
Constant.displayToast(getActivity(), getResources().getString(R.string.msg_internet));
}
}
我处理的结果如下:
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case FINE_LOCATION:
Constant.displayToast(getActivity(),"FINE_LOCATION");
Constant.displayLogE(">>>>","##"+"FINE_LOCATION");
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!Constant.checkPermission(MapFragment.this, ACCESS_COARSE_LOCATION)) {
Constant.requestPermission(MapFragment.this, ACCESS_COARSE_LOCATION, CORSE_LOCATION);
Constant.displayToast(getActivity(),"FINE_LOCATION calling inside");
}
Constant.displayLogE(">>>>","##"+"calling...");
Constant.displayToast(getActivity(),"FINE_LOCATION calling");
// locationUpdate();
}
break;
case CORSE_LOCATION:
Constant.displayLogE(">>>>","##"+"CORSE_LOCATION");
Constant.displayToast(getActivity(),"calling here...");
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Constant.displayLogE(">>>>","##"+"calling here...");
Constant.displayToast(getActivity(),"calling here...");
}
break;
case 101:
Constant.displayLogE(">>>>","##"+"CORSE_LOCATION");
break;
}
}
但是,我找不到案例101的日志:那是"" ##" +" CORSE_LOCATION""。 被困在这里......
可能是什么问题? 感谢。
答案 0 :(得分:-1)
由于您调用一个从回调中返回结果的函数,您应该在您的activity类而不是片段中编写回调函数,因为您的函数是由activity而不是fragment调用的。因此,只需将回调函数粘贴到您的活动代码中即可。请记住,如果您覆盖此功能,请务必将其称为超级功能。