问题描述
可能重复:
Programmatically获取设备的Android的API级别?
我如何得到curently运行我的应用程序在手机的API级别?我相信它的简单,但我不能找到它,因为所有我的搜索带来的垃圾达万吨。
How do I get the Api level of the phone curently running my application? I am sure its simple but I can not find it as all my searches bring up tons of junk.
推荐答案
检查的,这是保存各种条关于Android的信息的静态类OS的系统运行。
Check android.os.Build.VERSION
, which is a static class that holds various pieces of information about the Android OS a system is running.
如果你关心的所有版本的可能(返回到原来的Android版本),在的设置为任何小于4,那么你将不得不使用的,该是一个字符串
可以转换到释放的整数。
If you care about all versions possible (back to original Android version), as in minSdkVersion
is set to anything less than 4, then you will have to use android.os.Build.VERSION.SDK
, which is a String
that can be converted to the integer of the release.
如果你是在至少API版本4(Android 1.6的甜甜圈),获得API级别将是检查的,这是一个整数
If you are on at least API version 4 (Android 1.6 Donut), the current suggested way of getting the API level would be to check the value of android.os.Build.VERSION.SDK_INT
, which is an integer.
在两种情况下,整数从所有那些在。
In either case, the integer you get maps to an enum value from all those defined in android.os.Build.VERSION_CODES
.
SDK_INT value Build.VERSION_CODES Human Version Name
1 BASE Android 1.0 (no codename)
2 BASE_1_1 Android 1.1 Petit Four
3 CUPCAKE Android 1.5 Cupcake
4 DONUT Android 1.6 Donut
5 ECLAIR Android 2.0 Eclair
6 ECLAIR_0_1 Android 2.0.1 Eclair
7 ECLAIR_MR1 Android 2.1 Eclair
8 FROYO Android 2.2 Froyo
9 GINGERBREAD Android 2.3 Gingerbread
10 GINGERBREAD_MR1 Android 2.3.3 Gingerbread
11 HONEYCOMB Android 3.0 Honeycomb
12 HONEYCOMB_MR1 Android 3.1 Honeycomb
13 HONEYCOMB_MR2 Android 3.2 Honeycomb
14 ICE_CREAM_SANDWICH Android 4.0 Ice Cream Sandwich
15 ICE_CREAM_SANDWICH_MR1 Android 4.0.3 Ice Cream Sandwich
16 JELLY_BEAN Android 4.1 Jellybean
17 JELLY_BEAN_MR1 Android 4.2 Jellybean
18 JELLY_BEAN_MR2 Android 4.3 Jellybean
19 KITKAT Android 4.4 KitKat
20 KITKAT_WATCH Android 4.4 KitKat Watch
21 LOLLIPOP Android 5.0 Lollipop
22 LOLLIPOP_MR1 Android 5.1 Lollipop
23 M Android 6.0 Marshamallow
10000 CUR_DEVELOPMENT Current Development Build
这篇关于获取手机的Android API级别当前运行我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!