项目移植中,遇到需要区分不同系统版本的问题。于是查找相关方法如下:

android.os.Build类提供了当前系统信息。
可用if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD)这样来判断。

有人用这样一个函数来获取版本号:

public static int getAndroidSDKVersion() {
int version;
try {
version = Integer.valueOf(android.os.Build.VERSION.SDK);
} catch (NumberFormatException e) {
Log.e(e.toString());
}
return version;
}

android.os.Build.VERSION_CODES 值有如下,其中第二列的值就是API LEVEL编号:

int 1 (0x00000001) BASE October 2008: The original, first, version of Android.
int 2 (0x00000001) BASE_1_1 February 2009: First Android update, officially called 1.1.
int 3 (0x00000001) CUPCAKE May 2009: Android 1.5.
int 10000 (0x00002710) CUR_DEVELOPMENT Magic version number for a current development build, which has not yet turned into an official release.
int 5 (0x00000001) DONUT September 2009: Android 1.6.
int   ECLAIR November 2009: Android 2.0
  Applications targeting this or a later release will get these new changes in behavior:
5 (0x00000008) TheService.onStartCommandfunction will return the newSTART_STICKYbehavior instead of the old compatibilitySTART_STICKY_COMPATIBILITY.
int 6 (0x00000008) ECLAIR_0_1 December 2009: Android 2.0.1
int 7 (0x00000008) ECLAIR_MR1 January 2010: Android 2.1
int 8 (0x00000008) FROYO June 2010: Android 2.2
int GINGERBREAD November 2010: Android 2.3
  Applications targeting this or a later release will get these new changes in behavior:
9 (0x00000009) The application's notification icons will be shown on the new dark status bar background, so must be visible in this situation.
int 10 (0x0000000a) GINGERBREAD_MR1 February 2011: Android 2.3.3.
int 11 (0x0000000b) HONEYCOMB February 2011: Android 3.0.
int 12 (0x0000000c) HONEYCOMB_MR1 May 2011: Android 3.1.
int 13 (0x0000000d) HONEYCOMB_MR2 June 2011: Android 3.2.
int 14 (0x0000000e) ICE_CREAM_SANDWICH October 2011: Android 4.0.
int 15 (0x0000000f) ICE_CREAM_SANDWICH_MR1 December 2011: Android 4.0.3.
int 16 (0x00000010) JELLY_BEAN Android 4.1.

更多相关文章

  1. Nginx系列教程(六)| 手把手教你搭建 LNMP 架构并部署天空网络电影
  2. Android(安卓)framework系统默认设置修改
  3. Android(安卓)AlarmManager简单例子
  4. 显示所有APP的进程详细信息(进程ID、进程所在UID、进程占用内存、
  5. Android调用系统前置相机拍照
  6. Android(安卓)4.4 KitKat NotificationManagerService使用详解与
  7. Android模块化编程——WebView使用之系统返回键设置
  8. 在Android中获取系统正在运行的进程方法
  9. 微信内置浏览器UserAgent获取

随机推荐

  1. Xamarin 中开发Android实现全屏或者不显
  2. ArcGIS API For Android离线地图的实现
  3. Android(安卓)Bundle类
  4. [置顶] Android中万能适配器
  5. Dojo mobile TweetView 系列教程之五 —
  6. Android中删除常用联系人(下)
  7. 如何让Android下的多行edittext焦点光标
  8. Android该系统提供的服务--Vibrator(振子
  9. eclipse使用appcompat_v7库无法找到andro
  10. 两个星期的Android开发