2015-09-26 38 views
2

我想在我的应用程序中使用GCM Network Manager。该库需要在用户设备上安装版本为7.5及以上的Google Play Service。我想检查一下,如果安装了Google Play Services并且它的版本高于7.5。我做了如下:支持GCM网络管理器的Google Play服务的最低版本号是多少?

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

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

+0

可能对您有用,http://www.apk4fun.com/history/1155/ –

回答

2

基于对google Play Services这个answer版本的代码是简单地从它的版本代码创建了一个7位数的号码,这样7.5版本具有750万的版本代码。

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; 
} 
相关问题