package com.hjx.personalcenter.util; import android.content.Context; import android.content.pm.PackageManager; import com.hjx.personalcenter.activity.MyApplication; /** * Created by liujiaqi on 2018/4/11. */ public class VersionCodeUtils { /** * 获取当前本地apk的版本 * * @return */ public static int getVersionCode() { int versionCode = 0; try { //获取软件版本号,对应AndroidManifest.xml下android:versionCode versionCode = MyApplication.getInstance().getPackageManager(). getPackageInfo(MyApplication.getInstance().getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionCode; } /** * 获取版本号名称 * * @return */ public static String getVerName() { String verName = ""; try { verName = MyApplication.getInstance().getPackageManager(). getPackageInfo(MyApplication.getInstance().getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return verName; } }