Android examples for Android OS:OS Build
get API Version Number
//package com.java2s; import java.lang.reflect.Field; import android.os.Build; public class Main { @SuppressWarnings("unchecked") public static int getAPINumber() { // SDK_INT is available from API 4 if (isAPILevelLower4()) return 3; int version = 3; try {//from w ww.j a v a 2 s . c o m Class buildClass = Build.VERSION.class; Field sdkint = buildClass.getField("SDK_INT"); version = sdkint.getInt(null); } catch (Exception ignore) { } return version; } /** * Returns true when platform version is lower or equal to 1.5 * Since prior to 1.5 there was no Build.VERSION.SDK_INT available. * * @return return true or false */ public static boolean isAPILevelLower4() { return "1.5".compareTo(Build.VERSION.RELEASE) >= 0; } }