首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android GooglePlayServicesUtil.getErrorDialog()不显示该对话框

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

Stack Overflow用户
提问于 2013-10-01 00:17:11
回答 1查看 8.4K关注 0票数 11

我正在尝试在使用Google Play服务APK之前检查它的可用性。我有一个设备,它的软件包已过期(日志显示"...Google Play服务过期。需要3225100,但找到3136134")。

下面的代码将处理这种情况,并显示一个对话框,提示用户进行更新。出于我不知道的原因,这句话

代码语言:javascript
复制
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();

立即返回,不显示对话框(并且不会阻塞UI事件上的UI线程)。

您能说明一下可能发生的事情,以及如何纠正代码以显示对话框吗?

代码语言:javascript
复制
@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);
}    
EN

回答 1

Stack Overflow用户

发布于 2013-10-31 04:48:40

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19099005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档