14

当我尝试按照如何检查是否安装了 Google Play 服务的示例时,我收到以下错误:servicesConnected 方法内的行中的“connectionResult 无法解析”

int errorCode = connectionResult.getErrorCode();

可以缺少什么?我正在复制并粘贴它。我在这里按照示例

谢谢!

4

2 回答 2

43

这是示例中的错误。改用这个:

        } else {
        // Get the error code
        // Get the error dialog from Google Play services
        Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
                resultCode,
                this,
                CONNECTION_FAILURE_RESOLUTION_REQUEST);
于 2013-06-25T20:37:57.523 回答
1

它说缺少返回的解决方案是在 else 示例的末尾添加 return false :

else { // 获取错误代码

        // 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 
    }
于 2014-08-26T04:47:41.653 回答