76

How can I get the current Android SDK version(1.5, 1.6, 2.0, etc.) programmatically?

user
  • 85,380
  • 17
  • 189
  • 186
Arutha
  • 24,390
  • 25
  • 64
  • 80
  • 2
    Please edit the title of your question. Like "Retrieve android sdk version" – OneWorld Dec 09 '10 at 13:19
  • I'd like the answer to this as well. I'm not at the point where I can run tests so I can't print any constants out. I downloaded it about a month ago and can't find the version number. – Adamantus Mar 22 '12 at 14:10

2 Answers2

116

The String Build.VERSION.RELEASE will give you the user-visible version string (i.e 1.5, 1.6, 2.0), while Build.VERSION.SDK_INT will give you a value from Build.VERSION_CODES that would be better to use if you want to compare against it programatically.

Ross Rogers
  • 21,332
  • 23
  • 99
  • 156
Erich Douglass
  • 49,906
  • 11
  • 72
  • 60
  • 26
    Note that Build.VERSION.SDK_INT is only available on Android 1.6 and newer. Build.VERSION.SDK will work on all Android releases, including 1.5. However, once you elect to drop 1.5 support, switching to SDK_INT is a good idea. – CommonsWare Dec 10 '09 at 19:10
  • 2
    String readAbleAndroidVersion = android.os.Build.VERSION.RELEASE; – cV2 Jul 30 '11 at 19:20
  • The ActionBar compat lib uses the Build.VERSION_CODES.ICE_CREAM_SANDWICH constant and it doesn't crash on the 1.6 emulator. How can this happen? – jakk Sep 08 '12 at 20:36
25
  StringBuffer buf = new StringBuffer();

    buf.append("VERSION.RELEASE {"+Build.VERSION.RELEASE+"}");
    buf.append("\\nVERSION.INCREMENTAL {"+Build.VERSION.INCREMENTAL+"}");
    buf.append("\\nVERSION.SDK {"+Build.VERSION.SDK+"}");
    buf.append("\\nBOARD {"+Build.BOARD+"}");
    buf.append("\\nBRAND {"+Build.BRAND+"}");
    buf.append("\\nDEVICE {"+Build.DEVICE+"}");
    buf.append("\\nFINGERPRINT {"+Build.FINGERPRINT+"}");
    buf.append("\\nHOST {"+Build.HOST+"}");
    buf.append("\\nID {"+Build.ID+"}");

    Log.d("build",buf.toString()); 
Richa
  • 3,148
  • 1
  • 19
  • 25