2012-12-20 28 views
13

Android'de yeni Google Haritalar V2 API'sini kullanırken, cihazında Google Play (Hizmetler) uygulaması yüklü değilse kullanıcı bir hata mesajı görür. Bu hata mesajının stilini bir şekilde daha az sarsıcı hale getirmek ve uygulama stilini daha uygun hale getirmek için bir şekilde değiştirmenin mümkün olup olmadığını merak ediyorum.Android'de Google Play Hizmetleri hatası nasıl oluşturulur

This app won't run unless you update Google Play services.

+1

Nasıl ki getiriyorsunuz? GetErrorDialog() 'dan gelen sonuç neredeyse sarsıcı değildir. Bu, UI'nin bu bölümünü etkilemek için belgelenmiş hiçbir şey görmedim. – CommonsWare

+0

Sadece bir XML düzeninde gömülü harita parçasına sahibim. Oynatma servisleri eksikse bu içeriği gösterir. Hata iletişim seçeneği hakkında bilmiyordum! Bu iyi bir çözüm gibi görünüyor. – twaddington

+1

Evet, getErrorDialog() 'yoluna gidecektim. Maps V2 deneyiminin tüm kısmı berbat, ama 'getErrorDialog()' bana en az emmek için bana görünüyordu. :-) – CommonsWare

cevap

24

yaptıktan sonra bazı soruşturma, ben en iyi çözüm elle Google Play Hizmetleri kütüphanesinin olmadığını denetlemek ve özel bir hata görüntülemek olduğuna karar:

Bu

hata neye benzediği iletişim veya hata düzeni. GooglePlayServicesUtil 'da bazı fayda yöntemleri vardır, bu da bunu oldukça basitleştirmektedir.

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    int statusCode = 
      GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 
    if (statusCode == ConnectionResult.SUCCESS) { 
     // Continue with your regular activity/fragment configuration. 
    } else { 
     // Hide the map fragment so the default error message is not 
     // visible.  
     findViewById(R.id.map).setVisibility(View.GONE); 

     // Show a custom error message 
     showErrorMessage(statusCode); 
    } 
} 

private void showErrorMessage(final int statusCode) { 
    // I've outlined two solutions below. Pick which one works best for 
    // you and remove the if-block. 
    boolean showDialog = false; 

    if (showDialog) { 
     // This is the easiest method and simply displays a pre-configured 
     // error dialog 
     GooglePlayServicesUtil.getErrorDialog(statusCode, this, 0).show(); 
    } else { 
     // Show a completely custom layout 
     findViewById(R.id.error).setVisibility(View.VISIBLE); 

     // Wire up the button to install the missing library 
     Button errorButton = (Button) findViewById(R.id.error_button); 
     errorButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       try { 
        // Perform the correct action for the given status 
        // code! 
        GooglePlayServicesUtil.getErrorPendingIntent(
          statusCode, getActivity(), 0).send(); 
       } catch (CanceledException e1) { 
        // Pass 
       } 
      } 
     }); 
    } 
} 
+0

Ve düğme için uygun metin nasıl ayarlanır? –

+0

Uyarıyı göstermek için önce 'GooglePlayServicesUtil.isUserRecoverableError (statusCode)' seçeneğini kontrol etmek daha iyidir – bryant1410

0
  • GooglePlayServiceUtil kullanımdan kaldırıldı. En son arayüzler için GoogleApiAvailability'a bakın.
  • Doğrudan AlertDialog numaralı hata yerine sağlanan DialogFragment numarasını kullanmayı tercih edin, böylece etkinlik tarafından düzgün bir şekilde yönetilebilir.

    public static boolean checkPlayServices(FragmentActivity activity) { 
        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); 
        int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(activity); 
    
        if (resultCode != ConnectionResult.SUCCESS) { 
         if (googleApiAvailability.isUserResolvableError(resultCode)) { 
          // "user resolvable" means Google Play is available to download the last version of Play Services APK 
          // This will open Google dialog fragment displaying the proper message depending on "resultCode" 
          googleApiAvailability.showErrorDialogFragment(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST); 
         } else { 
          // Should not happen. This device does not support Play Services. 
          // Let's show an ultimate warning. 
          MyCustomPlayServicesErrorDialogFragment playServicesErrorDialog = new MyCustomPlayServicesErrorDialogFragment(); 
          playServicesErrorDialog.show(activity.getFragmentManager(), TAG); 
         } 
         return false; 
        } 
        return true; 
    } 
    
İlgili konular