在here和here之前已经提出过此问题,但没有有用的答案,因此我将尝试具体说明:我正在尝试在使用开发的应用上实施Google Cloud Messaging Android Studio 1.2.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
我完全卡住了。任何帮助将不胜感激。
答案 0 :(得分:0)
您的对话框未显示,因为创建对话框时UI线程中的执行不会暂停。这意味着应该在应该显示对话框后继续运行应用程序。如果您的代码执行如下操作:
showDialog();
startDifferentActivity();
用户无法与对话框进行交互,因为在对话框显示之前会启动不同的活动。如果您的代码执行取决于用户选择对话框的正/负/中性按钮或取消对话框,请实现相应的侦听器。