如何擷取Android版本號碼

來源:互聯網
上載者:User

As described in the android documentation, the SDK level (integer) the phone is running is available in:

android.os.Build.VERSION.SDK_INT;

The enum corresponding to this int is in the android.os.Build.VERSION_CODES class.

Code example:

int currentapiVersion=android.os.Build.VERSION.SDK_INT;
if(currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){

// Do something

}else{

// do something

}

Note:

This SDK_INT is available since Donut (android 1.6 / API4)

so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3)when you use it or your application will crash(thanks to Programmer Bruce for the precision).

====================================================================================

Build.VERSION_CODES

1 (0x00000001)           Android 1.0             BASE

2 (0x00000002)           Android 1.1             BASE_1_1

3 (0x00000003)           Android 1.5             CUPCAKE

4 (0x00000004)           Android 1.6             DONUT

5 (0x00000005)           Android 2.0             ECLAIR

6 (0x00000006)           Android 2.0.1          ECLAIR_0_1

7 (0x00000007)           Android 2.1             ECLAIR_MR1

8 (0x00000008)           Android 2.2             FROYO

9 (0x00000009)           Android 2.3             GINGERBREAD

10 (0x0000000a)         Android 2.3.3          GINGERBREAD_MR1

11 (0x0000000b)         Android 3.0             HONEYCOMB

12 (0x0000000c)         Android 3.1             HONEYCOMB_MR1

13 (0x0000000d)         Android 3.2             HONEYCOMB_MR2

Build.VERSION_CODES:http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.