Android 获取版本号

本文介绍了如何通过检查 Android 设备上运行的 SDK 版本来确定其操作系统版本,并提供了具体的代码示例。此外,还列出了从 Android 1.0 到 Android 3.2 的各个版本对应的 SDK 整数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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




Build.VERSION_CODES



参考推荐:

Android 获取屏幕尺寸与密度



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值