2015-09-26 39 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; 
} 
相關問題