Google Play Services example: “connectionResult cannot be resolved”

荒凉一梦 提交于 2020-01-01 08:01:29

问题


when I'm trying to follow the example on how to check if Google Play Services is installed I receive the following error: "connectionResult cannot be resolved" in the line inside servicesConnected method

int errorCode = connectionResult.getErrorCode();

What can be missing? I'm copying and pasting it. I'm following the example here

Thanks!


回答1:


It's a bug in the example. Use this instead:

        } else {
        // Get the error code
        // Get the error dialog from Google Play services
        Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
                resultCode,
                this,
                CONNECTION_FAILURE_RESOLUTION_REQUEST);



回答2:


the solution to where it said there was a missing return was to add return false at the end of the else so example:

else { // Get the error code

        // 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 
    }


来源:https://stackoverflow.com/questions/17303941/google-play-services-example-connectionresult-cannot-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!