android - 如何检查 Google Play 服务是否已从 android 中的代码启用/禁用

标签 android google-cloud-messaging google-play-services

我需要检查手机是否启用/禁用/可用/未安装播放服务。

我使用下面的代码

final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (status != ConnectionResult.SUCCESS) {
            Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
                      return false;
        } else {
            Log.i(TAG, GooglePlayServicesUtil.getErrorString(status));
                       return true;
        }

即使播放服务处于禁用状态,也会返回“2”。如何克服这个.?

最佳答案

你的方法很好。状态“2”表示 Google Play 服务可用但需要更新。检查 ConnectionResult 类的所有可能状态:

public static final int SUCCESS = 0;
public static final int SERVICE_MISSING = 1;
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
public static final int SERVICE_DISABLED = 3;
public static final int SIGN_IN_REQUIRED = 4;
public static final int INVALID_ACCOUNT = 5;
public static final int RESOLUTION_REQUIRED = 6;
public static final int NETWORK_ERROR = 7;
public static final int INTERNAL_ERROR = 8;
public static final int SERVICE_INVALID = 9;
public static final int DEVELOPER_ERROR = 10;
public static final int LICENSE_CHECK_FAILED = 11;
public static final int CANCELED = 13;
public static final int TIMEOUT = 14;
public static final int INTERRUPTED = 15;
public static final int API_UNAVAILABLE = 16;
public static final int SIGN_IN_FAILED = 17;

关于android - 如何检查 Google Play 服务是否已从 android 中的代码启用/禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32220798/

相关文章:

java - 无法解析符号 'GoogleCloudMessaging' GCM

android - google-map sdk map 设置 - 授权失败,确保以下内容与 API 控制台中的内容相对应

xamarin - 无法将构建操作设置为 GoogleServiceJson

java - logcat 充满 java.io.IOException : Connection refused messages

android - 如何在android的 TextView 中对长文本进行文本换行

android - TextView 的自动调整大小不起作用(Android O)

android - GoogleAccountCredential + Google Play Services + Refresh Token - 这如何协同工作?

java - 如何在一个 Activity 中使用java类?

使用 GCM 的 Android 聊天应用

ruby-on-rails - 如何在 Ruby on Rails 中注册服务 worker ?