获取未安装包的版本号
public static int getApkVerCode(Context c, String absPath) {
PackageManager pm = c.getPackageManager();PackageInfo pkgInfo = pm.getPackageArchiveInfo(absPath,
PackageManager.GET_ACTIVITIES);
if (pkgInfo == null)
return -1;
return pkgInfo.versionCode;
}
/**
* 获得手机端已经安装包版本号
*/
public static int getVerCode(Context c, String packageName) {
int verCode = -1;
try {
verCode = c.getPackageManager().getPackageInfo(packageName, 0).versionCode;
} catch (Exception e) {
System.out.println("版本号获取异常:" + e.getMessage());
}
return verCode;
}