支持GCM网络管理器的Google Play服务的最低版本代码是什么?

时间:2015-09-26 10:31:59

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

我想在我的应用程序中使用GCM Network Manager。此库需要在用户设备上安装Google Play Service版本7.5及更高版本。我想检查一下如果安装了Google Play Services并且其版本高于7.5。我做了如下:

private boolean isGcmNetworkManagerAvailable(Context context) {
    final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
    if (status != ConnectionResult.SUCCESS) {
        return false;
    }

    final String gpsPackageName = GooglePlayServicesUtil.GOOGLE_PLAY_SERVICES_PACKAGE;
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo gpsPackageInfo = pm.getPackageInfo(gpsPackageName,0);
        int versionCode = gpsPackageInfo.versionCode;
        //
        // What is the version code of Google Play Services version 7.5? 
        //
        if(versionCode < GOOGLE_PLAY_SERVICES_7_5_VERSION_CODE) {
            return false;
        }
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }

    return true;
}

问题是我不知道Google Play Services版本7.5的确切版本代码来检查此方法。

2 个答案:

答案 0 :(得分:2)

基于此answer版本代码google Play Services只是从其版本代码创建的7位数字,因此版本7.5具有7500000版本代码。

答案 1 :(得分:0)

希望这会有所帮助

/**
 * 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 {

        }
        return false;
    }
    return true;
}