Android GooglePlayServicesUtil.getErrorDialog() не отображает диалоговое окно ⇐ Android
-
Anonymous
Android GooglePlayServicesUtil.getErrorDialog() не отображает диалоговое окно
Я пытаюсь проверить доступность APK сервисов Google Play перед его использованием. У меня
устройство, на котором пакет устарел (в журнале указано: «...Сервисы Google Play устарели. Требуется 3225100, но найдено 3136134»).
Приведенный ниже код должен обрабатывать эту ситуацию и отображать диалоговое окно, предлагающее пользователю выполнить обновление. По неизвестной мне причине
строка
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
немедленно возвращает результат, не показывая диалога (и не блокируя поток пользовательского интерфейса при событии пользовательского интерфейса).
Не могли бы вы пролить свет? что возможно происходит и как исправить код, чтобы диалог отображался?
@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);
}
Подробнее здесь: https://stackoverflow.com/questions/190 ... the-dialog
Я пытаюсь проверить доступность APK сервисов Google Play перед его использованием. У меня
устройство, на котором пакет устарел (в журнале указано: «...Сервисы Google Play устарели. Требуется 3225100, но найдено 3136134»).
Приведенный ниже код должен обрабатывать эту ситуацию и отображать диалоговое окно, предлагающее пользователю выполнить обновление. По неизвестной мне причине
строка
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
немедленно возвращает результат, не показывая диалога (и не блокируя поток пользовательского интерфейса при событии пользовательского интерфейса).
Не могли бы вы пролить свет? что возможно происходит и как исправить код, чтобы диалог отображался?
@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);
}
Подробнее здесь: https://stackoverflow.com/questions/190 ... the-dialog