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

时间:2013-09-30 16:17:11

标签: android google-play-services


我在尝试使用之前检查 Google Play服务APK 的可用性。我有一个 包裹过期的设备(日志显示“ ... Google Play服务已过期。需要3225100但找到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);
}    

1 个答案:

答案 0 :(得分:0)

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