Google Play服务示例:“connectionResult无法解决”

14

我在尝试按照示例检查Google Play服务是否安装时,遇到以下错误:"connectionResult无法解析",出现在servicesConnected方法内的那一行。

int errorCode = connectionResult.getErrorCode();

有什么可能会丢失吗?我正在复制和粘贴它。我正在按照这里的示例进行操作。

谢谢!


1
真惊人,他们还没有修复它。我刚刚浪费了十分钟在这上面。 - cja
1
他们还没有修复它。 - Zapnologica
我在获取位置更新示例中发现了更多的错误。 - Zapnologica
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);

11
他们的servicesConnected()方法没有返回语句,真糟糕。 - Abx
是的... 我将所有这些问题报告给了 Google 文档团队作为漏洞。希望他们能采取行动解决这些问题。 - ocross
1
什么是resultCode和CONNECTION_FAILURE_RESOLUTION_REQUEST? - Tony

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 
    }

此外,如果您使用上述代码并且.show方法报告现有参数错误,请确保您正在为参数使用正确的DialogFragment; import android.support.v4.app.DialogFragment; (来源) - tutuDajuju

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接