版本号工具类
public class VersionUtils {
/**
* 获取本地软件版本号
*
* @param ctx
* @return
*/
public static int getLocalVersionCode(Context ctx) {
int localVersion =0;
try {
PackageInfo packageInfo = ctx.getApplicationContext()
.getPackageManager()
.getPackageInfo(ctx.getPackageName(), 0);
localVersion = packageInfo.versionCode;
}catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return localVersion;
}
/**
* 获取本地软件版本号名称
*/
public static StringgetLocalVersionName(Context ctx) {
String localVersion ="";
try {
PackageInfo packageInfo = ctx.getApplicationContext()
.getPackageManager()
.getPackageInfo(ctx.getPackageName(), 0);
localVersion = packageInfo.versionName;
}catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return localVersion;
}
}