你的位置:首页 > 操作系统

[操作系统]android 获取应用的当前版本号获取当前android系统的版本号


(转自:http://www.cnblogs.com/qsl568/archive/2012/03/14/2395636.html)

获取当前应用的版本号:

private String getVersionName() throws Exception  {      // 获取packagemanager的实例      PackageManager packageManager = getPackageManager();      // getPackageName()是你当前类的包名,0代表是获取版本信息      PackageInfo packInfo = packageManager.getPackageInfo(getPackageName(),0);      String versionName = packInfo.versionName;      String versionCode = packInfo.versionCode;      return version;  }

 

获取当前系统的版本号:

1 textView.setText("Product Model: " + android.os.Build.MODEL + "," 2         + android.os.Build.VERSION.SDK + "," 3         + android.os.Build.VERSION.RELEASE); 

或:

 1 /*  2  *  3  * Build.VERSION_CODES 4   1 (0x00000001)      Android 1.0       BASE 5   2 (0x00000002)      Android 1.1       BASE_1_1 6   3 (0x00000003)      Android 1.5       CUPCAKE 7   4 (0x00000004)      Android 1.6       DONUT 8   5 (0x00000005)      Android 2.0       ECLAIR 9   6 (0x00000006)      Android 2.0.1     ECLAIR_0_110   7 (0x00000007)      Android 2.1       ECLAIR_MR111   8 (0x00000008)      Android 2.2       FROYO12   9 (0x00000009)      Android 2.3       GINGERBREAD13   10 (0x0000000a)     Android 2.3.3     GINGERBREAD_MR114   11 (0x0000000b)     Android 3.0       HONEYCOMB15   12 (0x0000000c)     Android 3.1       HONEYCOMB_MR116   13 (0x0000000d)     Android 3.2       HONEYCOMB_MR2*/17   /*获取当前系统的android版本号*/18   int currentapiVersion=android.os.Build.VERSION.SDK_INT;