2

I want to use GCM Network Manager in my application. This library needs Google Play Service version 7.5 and above installed on user's device. I want to check that if Google Play Services is installed and its version is above 7.5. I did as below:

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;
}

Problem is that I don't know the exact version code of Google Play Services version 7.5 to check in this method.

Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106

2 Answers2

2

Based on this answer version code of google Play Services is simply a 7-digit number created from its version code so version 7.5 has 7500000 version code.

Community
  • 1
  • 1
Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106
0

Hope this will help

/**
 * 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;
}
Ravi Gadipudi
  • 1,446
  • 1
  • 17
  • 30