GooglePlayServicesUtil.getErrorDialog es nulo
Estoy utilizando ACRA ( arca.ch ) para generar informes de errores automáticos.
Acabo de publicar una nueva versión de mi aplicación mediante Google Maps Android API v2. Estoy recibiendo un error informado por los usuarios de EEEPad y Transformer Pad al intentar mostrar el cuadro de diálogo devuelto por GooglePlayServicesUtil.getErrorDialog. ¿Alguien sabe por qué esto podría suceder?
- Mover marcador con gps en google map android
- Problema de exactitud de Google maps
- Cómo tomar google Maps v2 snapshot?
- ¿Cómo puedo agregar un botón a la ventana de información de un marcador?
- Cómo cargar marcadores dinámicamente para la posición actual en google-maps de Android?
Aquí está el código relevante y Logcat según lo reportado por acra:
Mientras llamaba a esta línea:
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if(resultCode != ConnectionResult.SUCCESS) { //The dialog that comes back is null (probably due to the logcat message) Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 69); //So when I call the next line, the app crashes with a NullPointerException dialog.show(); } ...
Logcat:
12-18 04:21:04.531 W/GooglePlayServicesUtil( 3977): Google Play Store signature invalid. 12-18 04:21:04.551 E/GooglePlayServicesUtil( 3977): Google Play services is invalid. Cannot recover.
Gracias de antemano por cualquier ayuda que pueda proporcionar.
Actualizar
El problema aún no ha sido resuelto por google y actualizaré esta pregunta una vez que escuche algo (vea la respuesta de CommonsWare para el enlace de informe de errores de Google). Mientras tanto, si te encuentras con este problema y no quieres que tu aplicación se bloquee, esto es lo que estoy haciendo por el momento:
public void checkGooglePlayServicesAvailability() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if(resultCode != ConnectionResult.SUCCESS) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 69); if(dialog != null) { dialog.show(); } else { showOkDialogWithText(this, "Something went wrong. Please make sure that you have the Play Store installed and that you are connected to the internet. Contact developer with details if this persists."); } } Log.d("GooglePlayServicesUtil Check", "Result is: " + resultCode); } public static void showOkDialogWithText(Context context, String messageText) { Builder builder = new AlertDialog.Builder(context); builder.setMessage(messageText); builder.setCancelable(true); builder.setPositiveButton("OK", null); AlertDialog dialog = builder.create(); dialog.show(); }
- Google Maps v2, desaparecido 'android.support.v4.app.FragmentActivity'
- ¿Por qué google map v2 de repente se estrelló por java.lang.NullPointerException: Intento de obtener la longitud de matriz nula?
- Cierre de una actividad de otra clase
- Cómo mostrar mapa en android con marcador
- Cambiar Google Place Picker Appbar Text Color
- Google Maps, no hay opción para iniciar la navegación, sólo la vista previa está allí
- Obteniendo latitud y longitud utilizando gps cada 10 minutos en segundo plano android
- Lista de lugares cerrados sin utilizar un objeto de mapa en android
Google sugiere (también en docs ) llamar a getErrorDialog()
si el código de resultado es SERVICE_MISSING
, SERVICE_VERSION_UPDATE_REQUIRED
o SERVICE_DISABLED
. Por lo tanto, es posible que el último código de estado posible ( SERVICE_INVALID
) sea lo que causa problemas.
Estoy utilizando el siguiente código y hasta ahora parece que funciona bien (prueba en el emulador, la plataforma 2.3.3):
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity.getApplicationContext()); if (resultCode == ConnectionResult.SUCCESS) { activity.selectMap(); } else if (resultCode == ConnectionResult.SERVICE_MISSING || resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || resultCode == ConnectionResult.SERVICE_DISABLED) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 1); dialog.show(); }
Parece que tienes que comprobar con isUserRecoverableError
antes de intentar mostrar el diálogo.
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (status != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(status)) { GooglePlayServicesUtil.getErrorDialog(status, this, REQUEST_CODE_RECOVER_PLAY_SERVICES).show(); } else { Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show(); finish(); } }
Sobre la base del código de Rahim, agrego la capacidad de evitar que el usuario descarte el cuadro de diálogo de Servicios de Google Play (pulsando el botón Atrás) y continúe usando la aplicación sin los Servicios de Google Play instalados:
private void checkGooglePlayServicesAvailable() { int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (status != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(status)) { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, 0); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { MainActivity.this.finish(); } }); dialog.show(); } else { Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show(); finish(); } } }
Una actualización de la respuesta por @Nevermore , ya que los métodos de GooglePlayServicesUtil
están en desuso a favor de GoogleApiAvailability
:
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(activity.getApplicationContext()); if (resultCode == ConnectionResult.SUCCESS) { activity.selectMap(); } else if (resultCode == ConnectionResult.SERVICE_MISSING || resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || resultCode == ConnectionResult.SERVICE_DISABLED) { Dialog dialog = googleApiAvailability.getErrorDialog(activity, resultCode, 1); dialog.show(); }
Observe que el orden de los dos primeros parámetros en getErrorDialog()
se ha cambiado en la implementación de GoogleApiAvailability
.