我想在我的应用程序中使用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的确切版本代码来检查此方法。
答案 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;
}