9
我試圖在使用之前檢查谷歌Play服務APK的可用性。我有一個 設備,該軟件包已過期(日誌中顯示「... Google Play服務已過期,需要3225100,但找到了3136134」)。
下面的代碼應處理這種情況並顯示一個對話框,提示用戶進行更新。對於一種原因不明的,以我 行Android GooglePlayServicesUtil.getErrorDialog()不顯示對話框
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
最後按照建議做了,問題消失了。感謝提示。 – quirkfly
我仍然看到相同的問題。 Sho9uld圖書館出口?它可以在模擬器中工作,不過 – Jorge