gpt4 book ai didi

Android GooglePlayServicesUtil.getErrorDialog() 不显示对话框

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:21 26 4
gpt4 key购买 nike


我正在尝试在使用之前检查 Google Play Services APK 的可用性。我有一个包已过期的设备(日志显示为“...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);
}

最佳答案

当我在我的项目中不正确地包含 Google Play 服务库时,我遇到了一些类似于您的代码的奇怪行为。您必须作为项目导入 google-play-services_lib 目录并且您必须在类路径中包含 google-play-services.jar .原因是该项目包含大量资源,包括为 getErrorDialog() 显示适当对话框所必需的资源。

关于Android GooglePlayServicesUtil.getErrorDialog() 不显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com