取android:versionCode

/**

* @return 版本code
*/
public static String getVersionCode(Context cxt) {
PackageManager packageManager = cxt.getPackageManager();// 获取packagemanager的实例
PackageInfo packInfo = null;
try {
packInfo = packageManager.getPackageInfo(cxt.getPackageName(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
// 版本code 
return packInfo.versionCode + "";
}

你可能感兴趣的:(android)