-2

My application needs to determine if the device has the latest OS software provided by Google.

For example, currently, I need to be able to determine if the device is running Marshmallow, regardless of the fact that the phone may not ever be able to install Marshmallow.

Will this need to be something that is hard-coded into the application?

Thanks

markreed49
  • 41
  • 7
  • 2
    Why would you need this? Given that just because a new build was released, doesn't mean the device can get a version of it (most phones more or less never get an OS upgrade). At any rate there is no API or any way to code it into the OS, you'd need to set up a webservice that reports the latest released version and manually update it every time Google announces a new release. – Gabe Sechan Feb 03 '16 at 22:07
  • Look this answer http://stackoverflow.com/a/3993933/2802875 – Anton Holovin Feb 03 '16 at 22:08
  • I figured we would have to set it up as a web service, thank you for your reply. – markreed49 Feb 03 '16 at 22:09

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491