Asdescribedintheandroiddocumentation,theSDKlevel(integer)thephoneisrunningisavailablein:
android.os.Build.VERSION.SDK_INT;
Theenumcorrespondingtothisintisintheandroid.os.Build.VERSION_CODESclass.
Codeexample:
intcurrentapiVersion=android.os.Build.VERSION.SDK_INT;
if(currentapiVersion>=android.os.Build.VERSION_CODES.FROYO){
//Dosomething
}else{
//dosomething
}
Note:
ThisSDK_INTisavailablesinceDonut(android1.6/API4)
somakesureyourapplicationisnotretro-compatiblewithCupcake(android1.5/API3)whenyouuseitoryourapplicationwillcrash(thankstoProgrammerBrucefortheprecision).
====================================================================================
Build.VERSION_CODES
1(0x00000001)Android1.0BASE
2(0x00000002)Android1.1BASE_1_1
3(0x00000003)Android1.5CUPCAKE
4(0x00000004)Android1.6DONUT
5(0x00000005)Android2.0ECLAIR
6(0x00000006)Android2.0.1ECLAIR_0_1
7(0x00000007)Android2.1ECLAIR_MR1
8(0x00000008)Android2.2FROYO
9(0x00000009)Android2.3GINGERBREAD
10(0x0000000a)Android2.3.3GINGERBREAD_MR1
11(0x0000000b)Android3.0HONEYCOMB
12(0x0000000c)Android3.1HONEYCOMB_MR1
13(0x0000000d)Android3.2HONEYCOMB_MR2

参考推荐:
本文介绍了如何通过Android SDK中的`Build.VERSION.SDK_INT`获取当前设备的SDK版本,并通过`Build.VERSION_CODES`枚举类了解不同版本代码。示例代码展示了如何根据SDK版本进行逻辑判断,确保应用兼容性。
1万+

被折叠的 条评论
为什么被折叠?



