Get Android API level of phone currently running my application
Check android.os.Build.VERSION
, which is a static class that holds various pieces of information about the Android OS a system is running.
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.
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 Marshmallow
24 N Android 7.0 Nougat
25 N_MR1 Android 7.1.1 Nougat
26 O Android 8.0 Oreo
27 O_MR1 Android 8 Oreo MR1
28 P Android 9 Pie
29 Q Android 10
10000 CUR_DEVELOPMENT Current Development Version
Note that some time between Android N and O, the Android SDK began aliasing CUR_DEVELOPMENT
and the developer preview of the next major Android version to be the same SDK_INT
value (10000
).
How to check API level of device and use Actionbar if API is 11 or higher?
To remove this warning you need to tell the IDE you are aware that the methods/fileds/classes you use are available since later SDK than your minimum supported. This is done via @TargetApi
annotation. In your case @TargetApi(Build.VERSION_CODES.HONEYCOMB)
annotated method or the whole class.
Important: This will only remove the warning, you still have to ensure that these methods do NOT get called on devices where they don't exist.
Get Samsung KNOX api version on old devices like Jelly Bean
Preferred method: Get API Level as int
The documentation on EnterpriseDeviceManager.getAPILevel(); is wrong about the API level "Since: Knox API Level 24"!
EnterpriseDeviceManager.getAPILevel(); does actually work on old devices like the Samsung Galaxy Camera NX with Android 4.2.2 (returns 7) and Samsung Galaxy Camera 2 (returns 9) when using the backward compatibility library of KNOX (Knox SDK Support Library for Old Namespace Translation)!
Alternative method: Testing for methods
That's how we ended up testing for the KNOX Api level on old devices.
We looked for methods and classes in their documentation that only exist in certain API levels:
None of the virtual devices in android studio offer api 31, how can i run my code if i selected the api as =31?
I don't know why it not showing on your device, But on my device Manager, it properly shows up to 32, and Tiramisu
. See the below image. First, try to Refresh
, if more API 31,32 not show
then follow my second step.
2nd - If you do not find your API level in the Recommended
area, Just click on Other Images
as below image
You can see all of an API levels
here. If problem not solved yet, let me know
How can I check the system version of Android?
Check android.os.Build.VERSION
.
CODENAME
: The current development codename, or the string "REL" if this is a release build.INCREMENTAL
: The internal value used by the underlying source control to represent this build.RELEASE
: The user-visible version string.
Related Topics
When Should One Use Theme.Appcompat VS Themeoverlay.Appcompat
Why Do I Want to Avoid Non-Default Constructors in Fragments
Adding Items to Endless Scroll Recyclerview with Progressbar at Bottom
Android - Extracting Cookies After Login in Webview
How to Get Android Device Screen Size
Appcompatactivity.Oncreate Can Only Be Called from Within the Same Library Group
How to Make Android Apps Which Support Both 32-Bit and 64-Bit Architecture
Override Android Backbutton Behavior Only Works on the First Page with Phonegap
Buildconfig.Debug Always False When Building Library Projects with Gradle
How to Add Shortcut to Home Screen in Android Programmatically
Switching to Landscape Mode in Android Emulator
How to Display a List of Images in a Listview in Android
Fragments Onresume from Back Stack
How to Create a Relativelayout Programmatically with Two Buttons One on Top of the Other
How to Use the Same Keystore File to Sign Two Different Applications
How to Parse Same Name Tag in Android Xml Dom Parsing
How to Provide Animation When Calling Another Activity in Android