当我试图按照如何检查是否安装了Google Play服务的示例时,我收到以下错误:“connectionResult无法解析”在servicesConnected方法中的行
int errorCode = connectionResult.getErrorCode();
可能缺少什么?我正在复制并粘贴它。 我正在关注示例here
谢谢!
答案 0 :(得分:43)
这是示例中的错误。请改用:
} else {
// Get the error code
// Get the error dialog from Google Play services
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
resultCode,
this,
CONNECTION_FAILURE_RESOLUTION_REQUEST);
答案 1 :(得分:1)
它所说的缺少返回的解决方案是在else的结尾处添加return false这样的例子:
否则 { //获取错误代码
// Get the error dialog from Google Play services
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
resultCode,
this,
CONNECTION_FAILURE_RESOLUTION_REQUEST);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
// Create a new DialogFragment for the error dialog
ErrorDialogFragment errorFragment =
new ErrorDialogFragment();
// Set the dialog in the DialogFragment
errorFragment.setDialog(errorDialog);
// Show the error dialog in the DialogFragment
errorFragment.show(getSupportFragmentManager(),
"Location Updates");
}
return false;//THIS NEEDS TO BE FALSE
}