I was wondering how I could go about returning the name of the Android OS version (i.e. KitKat, JellyBean, etc) programatically. I'm able to find just about everything about the OS except the "codename", if you will. Any help is welcome, thanks.
Asked
Active
Viewed 4,908 times
3
-
Do you know how to get the VERSION_CODE? If so a quick switch statement will give you the code name. Not sure if this is easily available in the API directly. – Code-Apprentice Jun 29 '14 at 23:33
-
@Code-Apprentice - Yes I am able to get the version code, but I wanted to avoid mapping version codes to codenames myself if there was a simpler way to go about it. Gergo, I looked at a lot of SO questions, and probably came across that one, but I was curios if there was a more straightforward answer. Anyway, what I'll do it just make an array with code names and map the version codes to the array. Thanks for the input guys. – ArmaAK Jun 29 '14 at 23:43
1 Answers
10
I played around with an answer from the suggested question, found here, and came up with this one liner that returns the "codename" of the currently running OS version:
Build.VERSION_CODES.class.getFields()[android.os.Build.VERSION.SDK_INT].getName();
-
-
-
Build.VERSION_CODES.class.getFields()[26].getName() gives N_MR1, is one version off – lannyf Mar 25 '21 at 15:43
-
Gives error in android 11 - java.lang.ArrayIndexOutOfBoundsException: length=31; index=31 – Himani Jun 28 '21 at 09:31