2013-07-23 13 views
5

Sto aggiungendo un MapFragment alla mia app e avere il codice seguente, adattato da un tutorial mappe:pulsante finestra di errore GooglePlayServicesUtil non fa nulla

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

sto testando su un reset di fabbrica Galaxy Tab 10.1 con obsoleto servizi di gioco di google. Quindi quando provo ad aprire MapFragment, chiamo lo servicesConnected() per controllare e, come previsto, ottengo una finestra di dialogo che mi dice che ho bisogno di Google Play Services. Nella parte inferiore della finestra di dialogo è presente un pulsante "Ottieni servizi Google Play" ma quando faccio clic su di esso, non fa nulla. Il mio LogCat produce il seguente 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 

Ho la onConnectionFailed seguente metodo (sostanzialmente una copia-incolla dal sito dello sviluppatore Android):

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(); 
    } 
} 

Perché non è questo lavoro? Qualsiasi aiuto sarebbe grande.

Here 's la pagina dev di Android da cui lavoro, e here' s un post SO relativo ad esso pure.

Modifica

mi sono reso conto che non avevo un account Google configurato sul dispositivo in modo da crearne uno, ma non faceva alcuna differenza.

risposta

3

Questo codice sta lavorando per 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(); 
     } 
    }); 
} 
+0

Ho provato questo e ha funzionato una volta ma era disordinato. Così ho cambiato un altro codice, disinstallato i servizi di Google Play e ho provato di nuovo e non funziona. Ho annullato tutte le mie modifiche e ancora non funziona ... –

+0

Ora funziona di nuovo. Senza cambiare una cosa –

+0

Il codice "non dovrebbe" eseguire su quella linea, ma nel caso in cui: si chiama dialog.show() all'interno dell'istruzione if (dialog == null) – Ripityom

0

mi sono imbattuto lo stesso problema. Il problema è che la finestra di dialogo dovrebbe essere creata nella discussione dell'interfaccia utente e che la funzione show() debba essere chiamata anche nel thread dell'interfaccia utente.

Problemi correlati