-2

Is there a helper method built into Android that would let me get the platform version from the api level?

eg. I pass in 21 and get back the string "5.0"

I have created a utility but this is hard coded and would require updating. I was hoping this was something I missed.

StuStirling
  • 15,601
  • 23
  • 93
  • 150
  • You can update your class to use an xml file or a database table, ... whatever. So the updates will be very fast and straight. – Phantômaxx Feb 12 '15 at 20:51

1 Answers1

1

To get a list of the build versions vs. API, check here:

Get Android API level of phone currently running my application

However, it sounds like you really want to get the API / version number of a particular install. That is mentioned in that link under android.os.Build.VERSION - and if you want to display something meaningful to the user, then use the RELEASE field or a static String array from the table.

If you really need the "reverse lookup" like your question suggests, then it is not possible without the table. Older versions of Android will not know the release versions or valid API numbers of future versions, of course. In other words, as we are currently on 5.0 and API 21, do you know if there will be API 22 and version 5.0 also? Like version 4.4 has 2 API numbers (19 and 20). Your code will not always run on every device unless you hard-code "future releases" for older devices.

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36