Will this need to be something that is hard-coded into the application?
Yes, more or less. You could use reflection to examine the values in Build.VERSION_CODES
and see which is the highest in the continuous range starting with 1.
However, those values are compiled into your app; they are not coming from the framework, as they are static final int
values. So, while this approach would work for current and future versions of Android, you have to build your app with the latest compileSdkVersion
, ship that updated app (which will now pull in a higher max version code), and rely on users to update the app.
If you don't want that — for example, you don't want to rely on users updating the app — you will need to pull the latest-version information from the Internet, preferably from some host that you control.