【问题标题】:GooglePlayServicesUtil.getErrorDialog doesn't workGooglePlayServicesUtil.getErrorDialog 不起作用
【发布时间】:2015-06-16 04:36:02
【问题描述】:

在here 和here 之前已经问过这个问题,但没有有用的答案,所以我会尝试具体一点:我正在尝试在使用 Android Studio 1.2 开发的应用上实现 Google Cloud Messaging。 2.我已经按照here 的说明安装了 Google Play 服务,并按照this sample 中的建议实现了checkPlayServices() 方法:

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;
}

如果设备没有 Google Play 服务或已过时,此方法应提醒用户并提供一个按钮以轻松安装/更新它。我在具有出厂设置的 Android 4.1.2 的三星 Galaxy S II 上测试该应用程序,因此它没有更新的 Google Play 服务。我已经确认调用了GooglePlayServicesUtil.getErrorDialog() 方法,但没有出现对话框。相反,我在 logcat 中得到了以下内容:

06-14 19:19:45.691  10616-10616/? I/dalvikvm﹕ Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
06-14 19:19:45.691  10616-10616/? W/dalvikvm﹕ VFY: unable to resolve virtual method 250: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
06-14 19:19:45.691  10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x00c2
06-14 19:19:45.691  10616-10616/? I/dalvikvm﹕ DexOpt: access denied from Lcom/google/android/gms/common/GooglePlayServicesUtil; to field Landroid/app/Notification;.extras
06-14 19:19:45.691  10616-10616/? W/dalvikvm﹕ VFY: unable to resolve instance field 18
06-14 19:19:45.691  10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x54 at 0x00e1
06-14 19:19:45.691  10616-10616/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
06-14 19:19:45.691  10616-10616/? W/dalvikvm﹕ VFY: unable to resolve check-cast 27 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
06-14 19:19:45.691  10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x000e
06-14 19:19:45.696  10616-10616/? I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
06-14 19:19:45.696  10616-10616/? W/dalvikvm﹕ VFY: unable to resolve virtual method 542: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
06-14 19:19:45.696  10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
06-14 19:19:45.696  10616-10616/? W/GooglePlayServicesUtil﹕ Google Play services out of date.  Requires 7571000 but found 2012110

我完全被困住了。任何帮助将不胜感激。

【问题讨论】:

    标签: android android-studio google-play-services


    【解决方案1】:

    您的对话框未显示,因为在创建对话框时 UI 线程中的执行并未暂停。这意味着您的应用程序将在应该显示对话框后继续运行。如果您的代码执行以下操作:

    showDialog();
    startDifferentActivity();
    

    用户将无法与对话框交互,因为不同的活动会在对话框显示之前启动。如果您的代码执行依赖于用户选择对话框的正/负/中性按钮或关闭对话框,请实现适当的侦听器。

    【讨论】:

    • 我刚刚尝试了你的建议,但我得到了同样的错误。它以I/dalvikvm﹕ Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza 开头,以W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 2012110 结尾。
    • 你的代码返回后做什么?应用程序会崩溃吗?你说方法getErrorDialog()被调用但没有出现。这可能是因为当显示对话框时,UI 线程中的执行在等待用户与对话框交互时不会暂停。这意味着您的函数返回并继续执行,因此如果您要执行诸如创建对话框然后启动新活动之类的操作,则该对话框将永远不会出现,因为您的新活动将开始。
    • 你能编辑你的答案吗?这是前面评论中描述的有效方法。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2012-12-05
    • 2017-04-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    相关资源
    最近更新 更多