Android GooglePlayServicesUtil.getErrorDialog()不显示该对话框

我想在使用之前检查Google Play服务APK的可用性。 我有一个软件包已过期的设备(日志显示“ … Google Play服务已过期。需要3225100但find了3136134 ”)。
以下代码将处理此情况并显示一个对话框,提示用户执行更新。 由于我不知道的原因

GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show(); 

返回立即显示没有对话框 (并且不阻止UI事件上的UI线程)。
您能否详细说明可能发生的事情以及如何纠正代码以显示对话框?

 @Override protected void onResume() { super.onResume(); // Check device for Play Services APK. If check succeeds, proceed with // GCM registration. if (checkPlayServices()) { gcm = GoogleCloudMessaging.getInstance(this); regid = getRegistrationId(context); if (regid == null || regid.length() == 0) { registerInBackground(); } else { this.user.setGCMRegistrationId(regid); } } else { Log.i(TAG, "No valid Google Play Services APK found."); } } /** * Check the device to make sure it has the Google Play Services APK. If * it doesn't, display a dialog that allows users to download the APK from * the Google Play Store or enable it in the device's system settings. */ private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Log.i(TAG, "This device is not supported."); finish(); } return false; } return true; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PLAY_SERVICES_RESOLUTION_REQUEST: if (resultCode == RESULT_CANCELED) { Toast.makeText(this, "Google Play Services must be installed.", Toast.LENGTH_SHORT).show(); finish(); } return; } super.onActivityResult(requestCode, resultCode, data); } 

当我在项目中不正确地包含Google Play服务库时,我遇到了一些类似于你的代码的奇怪行为。 您必须将google-play-services_lib目录作为项目导入, 并且必须在类路径中包含google-play-services.jar。 原因是该项目包含一堆资源,包括显示getErrorDialog()的相应对话框所需的资源。