获得自己程序的版本
private String mVersion; public String longVersion() { if (mVersion == null) { PackageManager pm = getPackageManager(); PackageInfo pi; try { pi = pm.getPackageInfo(getPackageName(), 0); mVersion = pi.versionName; } catch (NameNotFoundException e) { mVersion = ""; // failed, ignored } } return mVersion; } public String shortVersion() { String v = longVersion(); v = v.substring(0, v.lastIndexOf('.')); return v; }
?