获得android应用的版本号

在开发的过程中,需要获得版本号

 1     private PackageInfo getVersion() {
 2         PackageManager packageManager = MyApplication.getInstance().getPackageManager();
 3         PackageInfo packageInfo = null;
 4         try {
 5             packageInfo = packageManager.getPackageInfo(MyApplication.getInstance().getPackageName(), 0);
 6         } catch (NameNotFoundException e) {
 7             // TODO Auto-generated catch block
 8             e.printStackTrace();
 9         }
10         return packageInfo;
11     }
12 
13     private String getVersionName() {
14         return getVersion().versionName;
15     }
16 
17     private String getVersionCode() {
18         return String.valueOf(getVersion().versionCode);
19     }

 

 

==完

posted @ 2016-03-07 11:29  HuijunZhang  阅读(298)  评论(0编辑  收藏  举报
中国