You can use Build.VERSION.SDK, which returns String and is available for all versions of Android up to 1.6. It is marked as deprecated, so you should use reflection to make sure your application does not encounter problems in future versions of Android.
So, to ensure that all versions are <1.6, you can use a modified version of Alexs code;
public static int getPlatformVersion() { try { Field verField = Class.forName("android.os.Build$VERSION").getField("SDK_INT"); int ver = verField.getInt(verField); return ver; } catch (Exception e) { try { Field verField = Class.forName("android.os.Build$VERSION").getField("SDK"); String verString = (String) verField.get(verField); return Integer.parseInt(verString); } catch(Exception e) { return -1; } } }
source share