我正在尝试在使用Google Play服务之前检查其可用性。我有一个设备,其中该软件包已过时(日志显示“...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);
}
getErrorDialog
仍然没有任何作用。 - theblang