3

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.

ArmaAK
  • 587
  • 6
  • 21
  • 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 Answers1

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();
Community
  • 1
  • 1
ArmaAK
  • 587
  • 6
  • 21