Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GooglePlayServicesUtil error dialog button does nothing

I'm adding a MapFragment to my app and have the following code, adapted from a maps tutorial:

private boolean servicesConnected() {
    // Check that Google Play services is available
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    // If Google Play services is available
    if (ConnectionResult.SUCCESS == resultCode) {
        // In debug mode, log the status
        Log.d("Location Updates", "Google Play services is available.");
        // Continue
        return true;

    // Google Play services was not available for some reason
    } else {
        GooglePlayServicesUtil.getErrorDialog(resultCode, this, 7).show();
        return false;
    }
}

I'm testing on a factory reset Galaxy tab 10.1 with outdated google play services. So when I attempt to open the MapFragment I call servicesConnected() to check and, as expected, I get a dialog telling me I need Google Play Services. At the bottom of the dialog it has a button "Get Google Play services" but when I click on it, it does nothing. My LogCat produces the following output:

07-23 15:30:43.580: W/GooglePlayServicesUtil(2515): Google Play services is missing.
07-23 15:30:48.510: E/SettingsRedirect(2515): Can't redirect to app settings for Google Play services

I have the following onConnectionFailed method (basically a copy-paste from the Android Developer site):

public void onConnectionFailed(ConnectionResult connectionResult) {
    /*
     * Google Play services can resolve some errors it detects.
     * If the error has a resolution, try sending an Intent to
     * start a Google Play services activity that can resolve
     * error.
     */
    if (connectionResult.hasResolution()) {
        try {
            // Start an Activity that tries to resolve the error
            connectionResult.startResolutionForResult(
                    this,
                    CONNECTION_FAILURE_RESOLUTION_REQUEST);
            /*
             * Thrown if Google Play services canceled the original
             * PendingIntent
             */
        } catch (IntentSender.SendIntentException e) {
            // Log the error
            e.printStackTrace();
        }
    } else {
        /*
         * If no resolution is available, display a dialog to the
         * user with the error.
         */
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 7).show();
    }
}

Why isn't this working? Any help would be great.

Here's the Android dev page I'm working from, and here's a SO post related to it as well.

Edit

I realised I didn't have a Google Account set up on the device so I set one up, but it made no difference.

like image 459
Mike T Avatar asked Oct 22 '22 04:10

Mike T


1 Answers

This code is working for me :

boolean checkGooglePlayServicesAvailable() {
    final int connectionStatusCode = GooglePlayServicesUtil
        .isGooglePlayServicesAvailable(getActivity());
    Log.i(DEBUG_TAG,
    "checkGooglePlayServicesAvailable, connectionStatusCode="
    + connectionStatusCode);
    if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
        showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
        return false;
    }
    Toast t = Toast.makeText(getActivity(),
        "Google Play service available", Toast.LENGTH_LONG);
    t.show();
    return true;
}

void showGooglePlayServicesAvailabilityErrorDialog(
    final int connectionStatusCode) {
    getActivity().runOnUiThread(new Runnable() {
    public void run() {
    final Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
        connectionStatusCode, getActivity(),
        REQUEST_GOOGLE_PLAY_SERVICES);
        if (dialog == null) {
                Log.e(DEBUG_TAG,
                        "couldn't get GooglePlayServicesUtil.getErrorDialog");
                Toast.makeText(getActivity(),
                        "incompatible version of Google Play Services",
                        Toast.LENGTH_LONG).show();
            }
            //this was wrong here -->dialog.show();
       }
    });
}
like image 172
Mikel Avatar answered Oct 24 '22 13:10

Mikel